From b560988bf949eec95fc850e4bf7fad9040260b55 Mon Sep 17 00:00:00 2001 From: Chris Cotter Date: Thu, 15 Oct 2020 12:00:02 -0400 Subject: [PATCH] test(storage): fix failing integration tests (#3027) 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 --- storage/integration_test.go | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/storage/integration_test.go b/storage/integration_test.go index efa43dbcf3a1..1f331e74da2d 100644 --- a/storage/integration_test.go +++ b/storage/integration_test.go @@ -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 { @@ -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) } @@ -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 @@ -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, @@ -2419,7 +2436,7 @@ 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, @@ -2427,7 +2444,7 @@ func TestIntegration_ReadCRC(t *testing.T) { }, { desc: "compressed, partial, server unzips", - obj: client.Bucket(gzippedBucket).Object(gzippedObject), + obj: client.Bucket(bucketName).Object(gzippedObject), offset: 1, length: 8, readCompressed: false, @@ -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,