From 37e38ad8b9514ec7b1f3b5de26742f5f52a51240 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 2 Sep 2014 22:26:11 -0700 Subject: [PATCH] schema: add disabled failing ForeachChunk test For blobkpacked. Change-Id: Id133032aed21c9beeb17aff08d2500281ed3a5a2 --- pkg/schema/fileread_test.go | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/pkg/schema/fileread_test.go b/pkg/schema/fileread_test.go index d507171fb..ff0629717 100644 --- a/pkg/schema/fileread_test.go +++ b/pkg/schema/fileread_test.go @@ -365,6 +365,74 @@ func TestReaderForeachChunk(t *testing.T) { } } +func TestForeachChunkAllSchemaBlobs(t *testing.T) { + sto := new(test.Fetcher) // in-memory blob storage + foo := &test.Blob{"foo"} + bar := &test.Blob{"bar"} + sto.AddBlob(foo) + sto.AddBlob(bar) + + // Make a "bytes" schema blob referencing the "foo" and "bar" chunks. + // Verify it works. + bytesBlob := &test.Blob{`{"camliVersion": 1, +"camliType": "bytes", +"parts": [ + {"blobRef": "` + foo.BlobRef().String() + `", "size": 3}, + {"blobRef": "` + bar.BlobRef().String() + `", "size": 3} +]}`} + sto.AddBlob(bytesBlob) + + var fr *FileReader + mustRead := func(name string, br blob.Ref, want string) { + var err error + fr, err = NewFileReader(sto, bytesBlob.BlobRef()) + if err != nil { + t.Fatalf("%s: %v", name, err) + } + all, err := ioutil.ReadAll(fr) + if err != nil { + t.Fatalf("%s: %v", name, err) + } + if string(all) != want { + t.Errorf("%s: read contents %q; want %q", name, all, want) + } + } + mustRead("bytesBlob", bytesBlob.BlobRef(), "foobar") + + // Now make another bytes schema blob embedding the previous one. + bytesBlob2 := &test.Blob{`{"camliVersion": 1, +"camliType": "bytes", +"parts": [ + {"blobRef": "` + bytesBlob.BlobRef().String() + `", "size": 6} +]}`} + sto.AddBlob(bytesBlob2) + mustRead("bytesBlob2", bytesBlob2.BlobRef(), "foobar") + + sawSchema := map[blob.Ref]bool{} + sawData := map[blob.Ref]bool{} + if err := fr.ForeachChunk(func(sref blob.Ref, p BytesPart) error { + sawSchema[sref] = true + sawData[p.BlobRef] = true + t.Logf("chunk %v: %+v", sref, p) + return nil + }); err != nil { + t.Fatal(err) + } + t.Skipf("TODO(bradfitz): fix this test by changing the Foreach callback to give a schema []blob.Ref slice of the stack down to that chunk") + if !sawSchema[bytesBlob.BlobRef()] { + t.Error("didn't see bytesBlob") + } + if !sawSchema[bytesBlob2.BlobRef()] { + t.Error("didn't see bytesBlob2") + } + if !sawData[foo.BlobRef()] { + t.Error("didn't see foo") + } + if !sawData[bar.BlobRef()] { + t.Error("didn't see bar") + } +} + type summary []byte func (s summary) String() string {