Skip to content

Commit

Permalink
storage: readObject method for tests
Browse files Browse the repository at this point in the history
Add a method to simplify some tests.

Change-Id: I6e38ec01d9cfd8af72a45731ad9e1d9aa30ce39c
Reviewed-on: https://code-review.googlesource.com/8991
Reviewed-by: Jonathan Amsterdam <jba@google.com>
  • Loading branch information
jba committed Oct 31, 2016
1 parent 28994ff commit 67f57c5
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions storage/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,18 +519,13 @@ func TestObjects(t *testing.T) {
if err != nil {
t.Fatal(err)
}
rc, err := publicClient.Bucket(bucket).Object(publicObj).NewReader(ctx)
if err != nil {
t.Error(err)
}
slurp, err := ioutil.ReadAll(rc)

slurp, err := readObject(ctx, publicClient.Bucket(bucket).Object(publicObj))
if err != nil {
t.Errorf("ReadAll failed with %v", err)
}
if !bytes.Equal(slurp, contents[publicObj]) {
t.Errorf("readObject failed with %v", err)
} else if !bytes.Equal(slurp, contents[publicObj]) {
t.Errorf("Public object's content: got %q, want %q", slurp, contents[publicObj])
}
rc.Close()

// Test writer error handling.
wc := publicClient.Bucket(bucket).Object(publicObj).NewWriter(ctx)
Expand Down Expand Up @@ -567,7 +562,7 @@ func TestObjects(t *testing.T) {
if _, err := c.Run(ctx); err != nil {
t.Fatalf("ComposeFrom error: %v", err)
}
rc, err = compDst.NewReader(ctx)
rc, err := compDst.NewReader(ctx)
if err != nil {
t.Fatalf("compDst.NewReader: %v", err)
}
Expand Down Expand Up @@ -797,20 +792,24 @@ func TestZeroSizedObject(t *testing.T) {
defer obj.Delete(ctx)

// Check we can read it too.
r, err := obj.NewReader(ctx)
body, err := readObject(ctx, obj)
if err != nil {
t.Fatalf("NewReader: %v", err)
}
defer r.Close()
body, err := ioutil.ReadAll(r)
if err != nil {
t.Fatalf("ioutil.ReadAll: %v", err)
t.Fatalf("readObject: %v", err)
}
if len(body) != 0 {
t.Errorf("Body is %v, want empty []byte{}", body)
}
}

func readObject(ctx context.Context, obj *ObjectHandle) ([]byte, error) {
r, err := obj.NewReader(ctx)
if err != nil {
return nil, err
}
defer r.Close()
return ioutil.ReadAll(r)
}

// cleanup deletes the bucket used for testing, as well as old
// testing buckets that weren't cleaned previously.
func cleanup() error {
Expand Down

0 comments on commit 67f57c5

Please sign in to comment.