github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/execution/ingestion/uploader/gcp_uploader_test.go (about) 1 package uploader 2 3 import ( 4 "bytes" 5 "context" 6 "io" 7 "os" 8 "testing" 9 10 "cloud.google.com/go/storage" 11 "github.com/rs/zerolog" 12 "github.com/stretchr/testify/require" 13 14 testutils "github.com/onflow/flow-go/utils/unittest" 15 ) 16 17 func Test_GCPBucketUploader(t *testing.T) { 18 testutils.SkipUnless(t, testutils.TEST_REQUIRES_GCP_ACCESS, "requires GCP Bucket setup") 19 20 bucketName := os.Getenv("FLOW_TEST_GCP_BUCKET_NAME") 21 if bucketName == "" { 22 t.Fatal("please set FLOW_TEST_GCP_BUCKET_NAME environmental variable") 23 } 24 uploader, err := NewGCPBucketUploader(context.Background(), bucketName, zerolog.Nop()) 25 require.NoError(t, err) 26 27 cr, _ := generateComputationResult(t) 28 29 buffer := &bytes.Buffer{} 30 err = WriteComputationResultsTo(cr, buffer) 31 require.NoError(t, err) 32 33 err = uploader.Upload(cr) 34 35 require.NoError(t, err) 36 37 // check uploaded object 38 client, err := storage.NewClient(context.Background()) 39 require.NoError(t, err) 40 bucket := client.Bucket(bucketName) 41 42 objectName := GCPBlockDataObjectName(cr) 43 44 reader, err := bucket.Object(objectName).NewReader(context.Background()) 45 require.NoError(t, err) 46 47 readBytes, err := io.ReadAll(reader) 48 require.NoError(t, err) 49 50 require.Equal(t, buffer.Bytes(), readBytes) 51 }