Skip to content

Commit 936c517

Browse files
committed
fix(gcp): satisfy lint in TestMissingStaticTokenFallsBackToADC
Replace os.Setenv-in-cleanup with t.Setenv (the cleanup it registers is sufficient for restoration) and add the blank line wsl_v5 wants before the unsetenv call.
1 parent 2df70d6 commit 936c517

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

modules/gcp/static_token_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ func TestStaticTokenShortCircuitsCredentialLookup(t *testing.T) {
3333
}
3434

3535
// Without the static token env var, constructors must fall back to ADC, which
36-
// fails when the credentials file is poisoned.
36+
// fails when the credentials file is poisoned. t.Setenv records the original
37+
// value and registers cleanup; the subsequent Unsetenv triggers the "not set"
38+
// branch in getStaticTokenSource for the duration of the test.
3739
func TestMissingStaticTokenFallsBackToADC(t *testing.T) {
38-
orig, had := os.LookupEnv("GOOGLE_OAUTH_ACCESS_TOKEN")
40+
t.Setenv("GOOGLE_OAUTH_ACCESS_TOKEN", "")
3941
require.NoError(t, os.Unsetenv("GOOGLE_OAUTH_ACCESS_TOKEN"))
40-
t.Cleanup(func() {
41-
if had {
42-
os.Setenv("GOOGLE_OAUTH_ACCESS_TOKEN", orig)
43-
}
44-
})
42+
4543
t.Setenv("GOOGLE_APPLICATION_CREDENTIALS", "/nonexistent/credentials.json")
4644

4745
_, err := gcp.NewCloudBuildServiceE(t)

0 commit comments

Comments
 (0)