Skip to content

Commit 42d0019

Browse files
refactor: remove duplicate tok.Token() (GoogleCloudPlatform#915)
1 parent 8c66e63 commit 42d0019

File tree

3 files changed

+1
-22
lines changed

3 files changed

+1
-22
lines changed

internal/cloudsql/lazy_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ func TestLazyRefreshCacheUpdateRefresh(t *testing.T) {
153153
t.Fatal(err)
154154
}
155155

156-
// Q: Why should the token provider be called twice?
157-
// A: Because the refresh code retrieves a token first (1 call) and then
158-
// refreshes it (1 call) for a total of 2 calls.
159-
if got, want := spy.callCount(), 2; got != want {
156+
if got, want := spy.callCount(), 1; got != want {
160157
t.Fatalf(
161158
"auth.TokenProvider call count, got = %v, want = %v",
162159
got, want,

internal/cloudsql/refresh.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,6 @@ func fetchEphemeralCert(
171171
tokErr,
172172
)
173173
}
174-
tok, tokErr = tp.Token(ctx)
175-
if tokErr != nil {
176-
return tls.Certificate{}, errtype.NewRefreshError(
177-
"failed to get Oauth2 token",
178-
inst.String(),
179-
tokErr,
180-
)
181-
}
182174
req.AccessToken = tok.Value
183175
}
184176
resp, err := retry50x(ctx, func(ctx2 context.Context) (*sqladmin.GenerateEphemeralCertResponse, error) {

internal/cloudsql/refresh_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,13 @@ func TestRefreshAdjustsCertExpiry(t *testing.T) {
240240
{
241241
desc: "when the token's expiration comes BEFORE the cert",
242242
resps: []tokenResp{
243-
{tok: &auth.Token{}},
244243
{tok: &auth.Token{Expiry: t1}},
245244
},
246245
wantExpiry: t1,
247246
},
248247
{
249248
desc: "when the token's expiration comes AFTER the cert",
250249
resps: []tokenResp{
251-
{tok: &auth.Token{}},
252250
{tok: &auth.Token{Expiry: t2}},
253251
},
254252
wantExpiry: certExpiry,
@@ -293,14 +291,6 @@ func TestRefreshWithIAMAuthErrors(t *testing.T) {
293291
resps: []tokenResp{{tok: nil, err: errors.New("fetch failed")}},
294292
wantCount: 1,
295293
},
296-
{
297-
desc: "when refreshing a token fails",
298-
resps: []tokenResp{
299-
{tok: &auth.Token{}, err: nil},
300-
{tok: nil, err: errors.New("refresh failed")},
301-
},
302-
wantCount: 2,
303-
},
304294
}
305295
cn := testInstanceConnName()
306296
inst := mock.NewFakeCSQLInstance("my-project", "my-region", "my-instance")

0 commit comments

Comments
 (0)