@@ -16,8 +16,10 @@ package storage
1616
1717import (
1818 "context"
19+ "errors"
1920 "fmt"
2021 "log"
22+ "net/url"
2123 "os"
2224 "strconv"
2325 "strings"
@@ -26,7 +28,10 @@ import (
2628
2729 "cloud.google.com/go/iam/apiv1/iampb"
2830 "github.com/google/go-cmp/cmp"
31+ "github.com/googleapis/gax-go/v2/apierror"
32+ "github.com/googleapis/gax-go/v2/callctx"
2933 "google.golang.org/api/iterator"
34+ "google.golang.org/grpc/codes"
3035)
3136
3237var emulatorClients map [string ]storageClient
@@ -1342,6 +1347,47 @@ func TestObjectConditionsEmulated(t *testing.T) {
13421347 })
13431348}
13441349
1350+ // Test that RetryNever prevents any retries from happening in both transports.
1351+ func TestRetryNeverEmulated (t * testing.T ) {
1352+ transportClientTest (t , func (t * testing.T , project , bucket string , client storageClient ) {
1353+ ctx := context .Background ()
1354+
1355+ attrs , err := client .CreateBucket (ctx , project , bucket , & BucketAttrs {}, nil )
1356+ if err != nil {
1357+ t .Fatalf ("creating bucket: %v" , err )
1358+ }
1359+
1360+ // Need the HTTP hostname to set up a retry test, as well as knowledge of
1361+ // underlying transport to specify instructions.
1362+ host := os .Getenv ("STORAGE_EMULATOR_HOST" )
1363+ endpoint , err := url .Parse (host )
1364+ if err != nil {
1365+ t .Fatalf ("parsing endpoint: %v" , err )
1366+ }
1367+ var transport string
1368+ if _ , ok := client .(* httpStorageClient ); ok {
1369+ transport = "http"
1370+ } else {
1371+ transport = "grpc"
1372+ }
1373+
1374+ et := emulatorTest {T : t , name : "testRetryNever" , resources : resources {},
1375+ host : endpoint }
1376+ et .create (map [string ][]string {"storage.buckets.get" : {"return-503" }}, transport )
1377+ ctx = callctx .SetHeaders (ctx , "x-retry-test-id" , et .id )
1378+ _ , err = client .GetBucket (ctx , attrs .Name , nil , withRetryConfig (& retryConfig {policy : RetryNever }))
1379+
1380+ var ae * apierror.APIError
1381+ if errors .As (err , & ae ) {
1382+ // We espect a 503/UNAVAILABLE error. For anything else including a nil
1383+ // error, the test should fail.
1384+ if ae .GRPCStatus ().Code () != codes .Unavailable && ae .HTTPCode () != 503 {
1385+ t .Errorf ("GetBucket: got unexpected error %v; want 503" , err )
1386+ }
1387+ }
1388+ })
1389+ }
1390+
13451391// createObject creates an object in the emulator and returns its name, generation, and
13461392// metageneration.
13471393func createObject (ctx context.Context , bucket string ) (string , int64 , int64 , error ) {
0 commit comments