From 13c09072dbc8edf2e631da1bf143be3e81e12531 Mon Sep 17 00:00:00 2001 From: Aleksander Mistewicz Date: Wed, 21 Aug 2024 16:05:14 +0200 Subject: [PATCH] Accept 400 as a valid error code for zone/region that does not exist Bug: b/361065819 --- e2e/regions_test.go | 9 ++++++++- e2e/zones_test.go | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/e2e/regions_test.go b/e2e/regions_test.go index 36f98f26..63c15954 100644 --- a/e2e/regions_test.go +++ b/e2e/regions_test.go @@ -21,6 +21,7 @@ import ( "testing" "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta" + "google.golang.org/api/googleapi" ) func TestRegions(t *testing.T) { @@ -54,5 +55,11 @@ func TestRegions(t *testing.T) { const invalidZone = "moonlab1" _, err = theCloud.Regions().Get(ctx, meta.GlobalKey(invalidZone)) - checkErrCode(t, err, 404, "Regions.Get()") + gerr, ok := err.(*googleapi.Error) + if !ok { + t.Fatalf("Regions.Get(): invalid error type, want *googleapi.Error, got %T", err) + } + if gerr.Code != 400 && gerr.Code != 404 { + t.Fatalf("Regions.Get(): got code %d, want {400, 404} (err: %v)", gerr.Code, err) + } } diff --git a/e2e/zones_test.go b/e2e/zones_test.go index 0eb55870..4e873594 100644 --- a/e2e/zones_test.go +++ b/e2e/zones_test.go @@ -21,6 +21,7 @@ import ( "testing" "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta" + "google.golang.org/api/googleapi" ) func TestZones(t *testing.T) { @@ -54,5 +55,11 @@ func TestZones(t *testing.T) { const invalidZone = "moonlab1-c" _, err = theCloud.Zones().Get(ctx, meta.GlobalKey(invalidZone)) - checkErrCode(t, err, 404, "Zones.Get()") + gerr, ok := err.(*googleapi.Error) + if !ok { + t.Fatalf("Zones.Get(): invalid error type, want *googleapi.Error, got %T", err) + } + if gerr.Code != 400 && gerr.Code != 404 { + t.Fatalf("Zones.Get(): got code %d, want {400, 404} (err: %v)", gerr.Code, err) + } }