chore(storage): multi-transport test for RangeReader
Enable multi-transport testing for `TestIntegration_ObjectsRangeReader`. This also expands the test to do a content comparison using `go-cmp`.
We must temporarily skip gRPC due to a bug in how the StartOffset is reported in the response.
@@ -893,10 +893,8 @@ func TestIntegration_ConditionalDelete(t *testing.T) {
}
func TestIntegration_ObjectsRangeReader(t *testing.T) {
- ctx := context.Background()
- client := testConfig(ctx, t)
- defer client.Close()
- bkt := client.Bucket(bucketName)
+ multiTransportTest(skipGRPC("b/250958907"), t, func(t *testing.T, ctx context.Context, bucket string, _ string, client *Client) {
+ bkt := client.Bucket(bucket)
objName := uidSpace.New()
obj := bkt.Object(objName)
@@ -922,6 +920,7 @@ func TestIntegration_ObjectsRangeReader(t *testing.T) {
for _, last5 := range last5s {
t.Run(last5.name, func(t *testing.T) {
+ wantBuf := contents[len(contents)-5:]
r, err := obj.NewRangeReader(ctx, last5.start, last5.length)
if err != nil {
t.Fatalf("Failed to make range read: %v", err)
@@ -929,15 +928,19 @@ func TestIntegration_ObjectsRangeReader(t *testing.T) {
defer r.Close()
if got, want := r.Attrs.StartOffset, int64(len(contents))-5; got != want {
- t.Fatalf("StartOffset mismatch, got %d want %d", got, want)
+ t.Errorf("StartOffset mismatch, got %d want %d", got, want)
}
- nr, _ := io.Copy(ioutil.Discard, r)
+ gotBuf := &bytes.Buffer{}
+ nr, _ := io.Copy(gotBuf, r)
if got, want := nr, int64(5); got != want {
- t.Fatalf("Body length mismatch, got %d want %d", got, want)
+ t.Errorf("Body length mismatch, got %d want %d", got, want)
+ } else if diff := cmp.Diff(gotBuf.String(), string(wantBuf)); diff != "" {
+ t.Errorf("Content read does not match - got(-),want(+):\n%s", diff)
}
})
}
+ })
}
func TestIntegration_ObjectReadGRPC(t *testing.T) {
