Skip to content

Commit

Permalink
storage: add integration tests for object composition
Browse files Browse the repository at this point in the history
Issue googleapis#146

Change-Id: I4e9b146ea75ed5dd23e83b51e6ef0f66c8f68377
Reviewed-on: https://code-review.googlesource.com/7494
Reviewed-by: Jonathan Amsterdam <[email protected]>
  • Loading branch information
okdave committed Sep 12, 2016
1 parent 34b7f5b commit 5e5e8e5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions storage/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func TestIntegration_ConditionalDelete(t *testing.T) {
}

func TestObjects(t *testing.T) {
// TODO(djd): there are a lot of closely-related tests here which share
// a common setup. Once we can depend on Go 1.7 features, we should refactor
// this test to use the sub-test feature. This will increase the readability
// of this test, and should also reduce the time it takes to execute.
// https://golang.org/pkg/testing/#hdr-Subtests_and_Sub_benchmarks
ctx := context.Background()
client, bucket := testConfig(ctx, t)
defer client.Close()
Expand Down Expand Up @@ -484,6 +489,35 @@ func TestObjects(t *testing.T) {
if err != ErrObjectNotExist {
t.Errorf("Copy is expected to be deleted, stat errored with %v", err)
}

// Test object composition.
compDst := bkt.Object("composed")
var cmpSrcs []*ObjectHandle
var wantContents []byte
for _, obj := range objects {
cmpSrcs = append(cmpSrcs, bkt.Object(obj))
wantContents = append(wantContents, contents[obj]...)
}
if _, err := compDst.ComposeFrom(ctx, compSrcs, &ObjectAttrs{
ContentType: "text/json",
}); err != nil {
t.Fatalf("ComposeFrom error: %v", err)
}
rc, err = compDst.NewReader(ctx)
if err != nil {
t.Fatalf("compDst.NewReader: %v", err)
}
slurp, err = ioutil.ReadAll(rc)
if err != nil {
t.Fatalf("compDst ioutil.ReadAll: %v", err)
}
defer rc.Close()
if !bytes.Equal(slurp, wantContents) {
t.Errorf("Composed object contents\ngot: %q\nwant: %q", slurp, wantContents)
}
if got, want := rc.ContentType(), "text/json"; got != want {
t.Errorf("Composed object content-type = %q, want %q", got, want)
}
}

func testBucketList(t *testing.T, bkt *BucketHandle, objects []string) {
Expand Down

0 comments on commit 5e5e8e5

Please sign in to comment.