Skip to content

Commit

Permalink
Merge pull request #221 from AwesomePatrol/fix-361065819
Browse files Browse the repository at this point in the history
Accept 400 as a valid error code for zone/region that does not exist
  • Loading branch information
google-oss-prow[bot] authored Aug 21, 2024
2 parents fc9e5b0 + 13c0907 commit 6649a91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion e2e/regions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
9 changes: 8 additions & 1 deletion e2e/zones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 6649a91

Please sign in to comment.