Skip to content

Commit ff06fc2

Browse files
authored
fix: Fix default service account tests on GCE. (#11021)
Tests running on GCE VMs automatically fall back to using the local metadata service to detect the local default service account. In those cases, tests for malformed creds won't work, but they should return a VM-specific default service account email.
1 parent 6071167 commit ff06fc2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

β€Žstorage/bucket_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"testing"
2121
"time"
2222

23+
"cloud.google.com/go/compute/metadata"
2324
"cloud.google.com/go/internal/testutil"
2425
"cloud.google.com/go/storage/internal/apiv2/storagepb"
2526
"github.com/google/go-cmp/cmp"
@@ -1306,6 +1307,16 @@ func TestDetectDefaultGoogleAccessID(t *testing.T) {
13061307
if id != tc.serviceAccount {
13071308
t.Errorf("service account not found correctly; got: %s, want: %s", id, tc.serviceAccount)
13081309
}
1310+
} else if metadata.OnGCE() {
1311+
// On GCE, we fall back to the default service account. Check that's
1312+
// what happened.
1313+
defaultServiceAccount, err := metadata.Email("default")
1314+
if err != nil {
1315+
t.Errorf("could not load metadata service account for fallback: %v", err)
1316+
}
1317+
if id != defaultServiceAccount {
1318+
t.Errorf("service account not found correctly on fallback; got: %s, want: %s", id, defaultServiceAccount)
1319+
}
13091320
} else if err == nil {
13101321
t.Error("expected error but detectDefaultGoogleAccessID did not return one")
13111322
}

0 commit comments

Comments
 (0)