github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/file/s3file/bucketcache_test.go (about) 1 // Copyright 2018 GRAIL, Inc. All rights reserved. 2 // Use of this source code is governed by the Apache-2.0 3 // license that can be found in the LICENSE file. 4 5 package s3file 6 7 import ( 8 "context" 9 "flag" 10 "testing" 11 12 "github.com/aws/aws-sdk-go/aws" 13 awsrequest "github.com/aws/aws-sdk-go/aws/request" 14 "github.com/aws/aws-sdk-go/service/s3/s3iface" 15 "github.com/Schaudge/grailbase/errors" 16 "github.com/stretchr/testify/assert" 17 "github.com/stretchr/testify/require" 18 ) 19 20 var awsFlag = flag.Bool("aws", false, "If true, run tests that access AWS.") 21 22 func TestBucketRegion(t *testing.T) { 23 if !*awsFlag { 24 t.Skipf("skipping %s, pass -aws to run", t.Name()) 25 return 26 } 27 28 ctx := context.Background() 29 region := findBucketRegion(t, ctx, "grail-ccga2-evaluation-runs") 30 require.Equal(t, region, "us-west-2") 31 32 region = findBucketRegion(t, ctx, "grail-test-us-east-1") 33 require.Equal(t, region, "us-east-1") 34 35 region = findBucketRegion(t, ctx, "grail-test-us-east-2") 36 require.Equal(t, region, "us-east-2") 37 } 38 39 func findBucketRegion(t *testing.T, ctx context.Context, bucket string) string { 40 region, err := FindBucketRegion(ctx, bucket) 41 require.NoError(t, err) 42 return region 43 } 44 45 func TestBucketRegionCancellation(t *testing.T) { 46 ctx, cancel := context.WithCancel(context.Background()) 47 cancel() 48 _ = <-ctx.Done() 49 cache := bucketRegionCache{ 50 getBucketRegionWithClient: func(aws.Context, s3iface.S3API, string, ...awsrequest.Option) (string, error) { 51 return "", errors.E(errors.Temporary, "test transient error") 52 }, 53 } 54 _, err := cache.locate(ctx, "grail-ccga2-evaluation-runs") 55 assert.Contains(t, err.Error(), context.Canceled.Error()) 56 }