Skip to content

Commit

Permalink
test(storage): fix failing integration tests (#3027)
Browse files Browse the repository at this point in the history
TestIntegration_ReadCRC and TestIntegration_NoUnicodeNormalization
depended on data in a bucket which has seemingly been deleted.
This rewrites them so that they create their own data instead.

Fixes #3016
Fixes #3014
  • Loading branch information
tritone authored Oct 15, 2020
1 parent ed991e3 commit b560988
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions storage/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ func TestIntegration_NoUnicodeNormalization(t *testing.T) {
ctx := context.Background()
client := testConfig(ctx, t)
defer client.Close()
bkt := client.Bucket("storage-library-test-bucket")
bkt := client.Bucket(bucketName)
h := testHelper{t}

for _, tst := range []struct {
Expand All @@ -1885,6 +1885,8 @@ func TestIntegration_NoUnicodeNormalization(t *testing.T) {
{`"Cafe\u0301"`, "Normalization Form D"},
} {
name, err := strconv.Unquote(tst.nameQuoted)
w := bkt.Object(name).NewWriter(ctx)
h.mustWrite(w, []byte(tst.content))
if err != nil {
t.Fatalf("invalid name: %s: %v", tst.nameQuoted, err)
}
Expand Down Expand Up @@ -2353,16 +2355,31 @@ func TestIntegration_ReadCRC(t *testing.T) {
uncompressedBucket = "gcp-public-data-landsat"
uncompressedObject = "LC08/PRE/044/034/LC80440342016259LGN00/LC80440342016259LGN00_MTL.txt"

gzippedBucket = "storage-library-test-bucket"
gzippedObject = "gzipped-text.txt"
)
ctx := context.Background()
client, err := newTestClient(ctx, option.WithoutAuthentication())
client, err := newTestClient(ctx)
if err != nil {
t.Fatal(err)
}
h := testHelper{t}
defer client.Close()

// Create gzipped object.
var buf bytes.Buffer
zw := gzip.NewWriter(&buf)
zw.Name = gzippedObject
if _, err := zw.Write([]byte("gzipped object data")); err != nil {
t.Fatalf("creating gzip: %v", err)
}
if err := zw.Close(); err != nil {
t.Fatalf("closing gzip writer: %v", err)
}
w := client.Bucket(bucketName).Object(gzippedObject).NewWriter(ctx)
w.ContentEncoding = "gzip"
w.ContentType = "text/plain"
h.mustWrite(w, buf.Bytes())

for _, test := range []struct {
desc string
obj *ObjectHandle
Expand Down Expand Up @@ -2409,7 +2426,7 @@ func TestIntegration_ReadCRC(t *testing.T) {
// because it was computed against the zipped contents. We can detect
// this case using http.Response.Uncompressed.
desc: "compressed, entire file, unzipped",
obj: client.Bucket(gzippedBucket).Object(gzippedObject),
obj: client.Bucket(bucketName).Object(gzippedObject),
offset: 0,
length: -1,
readCompressed: false,
Expand All @@ -2419,15 +2436,15 @@ func TestIntegration_ReadCRC(t *testing.T) {
// When we read a gzipped file uncompressed, it's like reading a regular file:
// the served content and the CRC match.
desc: "compressed, entire file, read compressed",
obj: client.Bucket(gzippedBucket).Object(gzippedObject),
obj: client.Bucket(bucketName).Object(gzippedObject),
offset: 0,
length: -1,
readCompressed: true,
wantCheck: true,
},
{
desc: "compressed, partial, server unzips",
obj: client.Bucket(gzippedBucket).Object(gzippedObject),
obj: client.Bucket(bucketName).Object(gzippedObject),
offset: 1,
length: 8,
readCompressed: false,
Expand All @@ -2436,7 +2453,7 @@ func TestIntegration_ReadCRC(t *testing.T) {
},
{
desc: "compressed, partial, read compressed",
obj: client.Bucket(gzippedBucket).Object(gzippedObject),
obj: client.Bucket(bucketName).Object(gzippedObject),
offset: 1,
length: 8,
readCompressed: true,
Expand Down

0 comments on commit b560988

Please sign in to comment.