Repository: snowflakedb/gosnowflake
Pull request #651 (2022-09-06 02:33:45)

improve: use context.Background instead of context.TODO
### Description
I changed context.TODO to context.Background. context.Background equals context.TODO, so this change doesn't affect to any libs. But it's clear that the current implementation uses context, so we should use context.Background instead of context.TODO.

### Checklist
- [x] Code compiles correctly
- [x] Run ``make fmt`` to fix inconsistent formats
- [x] Run ``make lint`` to get lint errors and fix all of them
- [x] Created tests which fail without the change (if possible)
- [x] All tests passing
- [x] Extended the README / documentation, if necessary


sfc-gh-pfus: Thank you @sivchari  for your suggestion! You are obviously right. Can you rebase and solve conflicts?
sivchari: @sfc-gh-pfus 
I fixed it. Thanks for review 😄 
sfc-gh-pfus: Thank you @sivchari ! Is there any particular reason why you left this occurrences?

```
❯ grep -ir 'context.TODO'
./auth_test.go: _, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
./auth_test.go: _, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
./auth_test.go: _, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
./auth_test.go: sc.ctx = context.TODO()
./auth_test.go: _, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
./auth_test.go: _, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
./auth_test.go: _, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
./retry_test.go:        _, err = newRetryHTTP(context.TODO(),
./retry_test.go:        _, err = newRetryHTTP(context.TODO(),
./retry_test.go:        _, err = newRetryHTTP(context.TODO(),
./retry_test.go:        _, err = newRetryHTTP(context.TODO(),
./authexternalbrowser_test.go:  _, _, err := authenticateByExternalBrowser(context.TODO(), sr, authenticator, application, account, user, password, timeout)
./authexternalbrowser_test.go:  _, _, err = authenticateByExternalBrowser(context.TODO(), sr, authenticator, application, account, user, password, timeout)
./authexternalbrowser_test.go:  _, _, err = authenticateByExternalBrowser(context.TODO(), sr, authenticator, application, account, user, password, timeout)
./authexternalbrowser_test.go:  _, _, err := authenticateByExternalBrowser(context.TODO(), sr, authenticator, application, account, user, password, timeout)
❯ grep -ir 'context.TODO' | wc -l
      15
```
sivchari: I overlooked. I'll fix these args.
sivchari: @sfc-gh-pfus 
I fixed it.

Patch:
diff --git a/driver.go b/driver.go
index af29d66..6a565be 100644
--- a/driver.go
+++ b/driver.go
@@ -18,7 +18,7 @@ type SnowflakeDriver struct{}
 // Open creates a new connection.
 func (d SnowflakeDriver) Open(dsn string) (driver.Conn, error) {
 	logger.Info("Open")
-	ctx := context.TODO()
+	ctx := context.Background()
 	cfg, err := ParseDSN(dsn)
 	if err != nil {
 		return nil, err
diff --git a/ocsp.go b/ocsp.go
index 6feb716..297a999 100644
--- a/ocsp.go
+++ b/ocsp.go
@@ -751,7 +751,7 @@ func downloadOCSPCacheServer() {
 		Timeout:   timeout,
 		Transport: snowflakeInsecureTransport,
 	}
-	ret, ocspStatus := checkOCSPCacheServer(context.TODO(), ocspClient, http.NewRequest, u, timeout)
+	ret, ocspStatus := checkOCSPCacheServer(context.Background(), ocspClient, http.NewRequest, u, timeout)
 	if ocspStatus.code != ocspSuccess {
 		return
 	}
@@ -788,7 +788,7 @@ func getAllRevocationStatus(ctx context.Context, verifiedChains []*x509.Certific
 // verifyPeerCertificateSerial verifies the certificate revocation status in serial.
 func verifyPeerCertificateSerial(_ [][]byte, verifiedChains [][]*x509.Certificate) (err error) {
 	overrideCacheDir()
-	return verifyPeerCertificate(context.TODO(), verifiedChains)
+	return verifyPeerCertificate(context.Background(), verifiedChains)
 }
 
 func overrideCacheDir() {
diff --git a/restful.go b/restful.go
index f6948c4..6b10dd4 100644
--- a/restful.go
+++ b/restful.go
@@ -217,7 +217,7 @@ func postRestfulQuery(
 		return data, err
 	}
 
-	if err = sr.FuncCancelQuery(context.TODO(), sr, requestID, timeout); err != nil {
+	if err = sr.FuncCancelQuery(context.Background(), sr, requestID, timeout); err != nil {
 		return nil, err
 	}
 	return nil, ctx.Err()


Test patch:
diff --git a/auth_test.go b/auth_test.go
index 43123d7..c3a39a7 100644
--- a/auth_test.go
+++ b/auth_test.go
@@ -29,27 +29,27 @@ func TestUnitPostAuth(t *testing.T) {
 	bodyCreator := func() ([]byte, error) {
 		return []byte{0x12, 0x34}, nil
 	}
-	_, err = postAuth(context.TODO(), sr, sr.Client, &url.Values{}, make(map[string]string), bodyCreator, 0)
+	_, err = postAuth(context.Background(), sr, sr.Client, &url.Values{}, make(map[string]string), bodyCreator, 0)
 	if err != nil {
 		t.Fatalf("err: %v", err)
 	}
 	sr.FuncAuthPost = postAuthTestError
-	_, err = postAuth(context.TODO(), sr, sr.Client, &url.Values{}, make(map[string]string), bodyCreator, 0)
+	_, err = postAuth(context.Background(), sr, sr.Client, &url.Values{}, make(map[string]string), bodyCreator, 0)
 	if err == nil {
 		t.Fatal("should have failed to auth for unknown reason")
 	}
 	sr.FuncAuthPost = postAuthTestAppBadGatewayError
-	_, err = postAuth(context.TODO(), sr, sr.Client, &url.Values{}, make(map[string]string), bodyCreator, 0)
+	_, err = postAuth(context.Background(), sr, sr.Client, &url.Values{}, make(map[string]string), bodyCreator, 0)
 	if err == nil {
 		t.Fatal("should have failed to auth for unknown reason")
 	}
 	sr.FuncAuthPost = postAuthTestAppForbiddenError
-	_, err = postAuth(context.TODO(), sr, sr.Client, &url.Values{}, make(map[string]string), bodyCreator, 0)
+	_, err = postAuth(context.Background(), sr, sr.Client, &url.Values{}, make(map[string]string), bodyCreator, 0)
 	if err == nil {
 		t.Fatal("should have failed to auth for unknown reason")
 	}
 	sr.FuncAuthPost = postAuthTestAppUnexpectedError
-	_, err = postAuth(context.TODO(), sr, sr.Client, &url.Values{}, make(map[string]string), bodyCreator, 0)
+	_, err = postAuth(context.Background(), sr, sr.Client, &url.Values{}, make(map[string]string), bodyCreator, 0)
 	if err == nil {
 		t.Fatal("should have failed to auth for unknown reason")
 	}
@@ -131,7 +131,8 @@ func postAuthCheckOAuth(
 	_ *http.Client,
 	_ *url.Values, _ map[string]string,
 	bodyCreator bodyCreatorType,
-	_ time.Duration) (*authResponse, error) {
+	_ time.Duration,
+) (*authResponse, error) {
 	var ar authRequest
 	jsonBody, _ := bodyCreator()
 	if err := json.Unmarshal(jsonBody, &ar); err != nil {
@@ -408,7 +409,7 @@ func TestUnitAuthenticateWithTokenAccessor(t *testing.T) {
 	sc.rest = sr
 
 	// FuncPostAuth is set to fail, but AuthTypeTokenAccessor should not even make a call to FuncPostAuth
-	resp, err := authenticate(context.TODO(), sc, []byte{}, []byte{})
+	resp, err := authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err != nil {
 		t.Fatalf("should not have failed, err %v", err)
 	}
@@ -449,7 +450,7 @@ func TestUnitAuthenticate(t *testing.T) {
 	}
 	sc.rest = sr
 
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
@@ -458,7 +459,7 @@ func TestUnitAuthenticate(t *testing.T) {
 		t.Fatalf("Snowflake error is expected. err: %v", driverErr)
 	}
 	sr.FuncPostAuth = postAuthFailWrongAccount
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
@@ -467,7 +468,7 @@ func TestUnitAuthenticate(t *testing.T) {
 		t.Fatalf("Snowflake error is expected. err: %v", driverErr)
 	}
 	sr.FuncPostAuth = postAuthFailUnknown
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
@@ -477,7 +478,7 @@ func TestUnitAuthenticate(t *testing.T) {
 	}
 	ta.SetTokens("bad-token", "bad-master-token", 1)
 	sr.FuncPostAuth = postAuthSuccessWithErrorCode
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
@@ -491,7 +492,7 @@ func TestUnitAuthenticate(t *testing.T) {
 	}
 	ta.SetTokens("bad-token", "bad-master-token", 1)
 	sr.FuncPostAuth = postAuthSuccessWithInvalidErrorCode
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
@@ -501,7 +502,7 @@ func TestUnitAuthenticate(t *testing.T) {
 	}
 	sr.FuncPostAuth = postAuthSuccess
 	var resp *authResponseMain
-	resp, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	resp, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err != nil {
 		t.Fatalf("failed to auth. err: %v", err)
 	}
@@ -533,7 +534,7 @@ func TestUnitAuthenticateSaml(t *testing.T) {
 		Host:   "blah.okta.com",
 	}
 	sc.rest = sr
-	_, err = authenticate(context.TODO(), sc, []byte("HTML data in bytes from"), []byte{})
+	_, err = authenticate(context.Background(), sc, []byte("HTML data in bytes from"), []byte{})
 	if err != nil {
 		t.Fatalf("failed to run. err: %v", err)
 	}
@@ -550,7 +551,7 @@ func TestUnitAuthenticateOAuth(t *testing.T) {
 	sc.cfg.Token = "oauthToken"
 	sc.cfg.Authenticator = AuthTypeOAuth
 	sc.rest = sr
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err != nil {
 		t.Fatalf("failed to run. err: %v", err)
 	}
@@ -566,14 +567,14 @@ func TestUnitAuthenticatePasscode(t *testing.T) {
 	sc.cfg.Passcode = "987654321"
 	sc.rest = sr
 
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err != nil {
 		t.Fatalf("failed to run. err: %v", err)
 	}
 	sr.FuncPostAuth = postAuthCheckPasscodeInPassword
 	sc.rest = sr
 	sc.cfg.PasscodeInPassword = true
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err != nil {
 		t.Fatalf("failed to run. err: %v", err)
 	}
@@ -594,7 +595,7 @@ func TestUnitAuthenticateJWT(t *testing.T) {
 	sc.rest = sr
 
 	// A valid JWT token should pass
-	if _, err = authenticate(context.TODO(), sc, []byte{}, []byte{}); err != nil {
+	if _, err = authenticate(context.Background(), sc, []byte{}, []byte{}); err != nil {
 		t.Fatalf("failed to run. err: %v", err)
 	}
 
@@ -604,7 +605,7 @@ func TestUnitAuthenticateJWT(t *testing.T) {
 		t.Error(err)
 	}
 	sc.cfg.PrivateKey = invalidPrivateKey
-	if _, err = authenticate(context.TODO(), sc, []byte{}, []byte{}); err == nil {
+	if _, err = authenticate(context.Background(), sc, []byte{}, []byte{}); err == nil {
 		t.Fatalf("invalid token passed")
 	}
 }
@@ -619,20 +620,20 @@ func TestUnitAuthenticateUsernamePasswordMfa(t *testing.T) {
 	sc.cfg.Authenticator = AuthTypeUsernamePasswordMFA
 	sc.cfg.ClientRequestMfaToken = ConfigBoolTrue
 	sc.rest = sr
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err != nil {
 		t.Fatalf("failed to run. err: %v", err)
 	}
 
 	sr.FuncPostAuth = postAuthCheckUsernamePasswordMfaToken
 	sc.cfg.MfaToken = "mockedMfaToken"
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err != nil {
 		t.Fatalf("failed to run. err: %v", err)
 	}
 
 	sr.FuncPostAuth = postAuthCheckUsernamePasswordMfaFailed
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err == nil {
 		t.Fatal("should have failed")
 	}
@@ -648,7 +649,7 @@ func TestUnitAuthenticateWithConfigMFA(t *testing.T) {
 	sc.cfg.Authenticator = AuthTypeUsernamePasswordMFA
 	sc.cfg.ClientRequestMfaToken = ConfigBoolTrue
 	sc.rest = sr
-	sc.ctx = context.TODO()
+	sc.ctx = context.Background()
 	err = authenticateWithConfig(sc)
 	if err != nil {
 		t.Fatalf("failed to run. err: %v", err)
@@ -665,20 +666,20 @@ func TestUnitAuthenticateExternalBrowser(t *testing.T) {
 	sc.cfg.Authenticator = AuthTypeExternalBrowser
 	sc.cfg.ClientStoreTemporaryCredential = ConfigBoolTrue
 	sc.rest = sr
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err != nil {
 		t.Fatalf("failed to run. err: %v", err)
 	}
 
 	sr.FuncPostAuth = postAuthCheckExternalBrowserToken
 	sc.cfg.IDToken = "mockedIDToken"
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err != nil {
 		t.Fatalf("failed to run. err: %v", err)
 	}
 
 	sr.FuncPostAuth = postAuthCheckExternalBrowserFailed
-	_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
+	_, err = authenticate(context.Background(), sc, []byte{}, []byte{})
 	if err == nil {
 		t.Fatal("should have failed")
 	}
diff --git a/authexternalbrowser_test.go b/authexternalbrowser_test.go
index b8889a1..a6650dc 100644
--- a/authexternalbrowser_test.go
+++ b/authexternalbrowser_test.go
@@ -91,17 +91,17 @@ func TestUnitAuthenticateByExternalBrowser(t *testing.T) {
 		FuncPostAuthSAML: postAuthExternalBrowserError,
 		TokenAccessor:    getSimpleTokenAccessor(),
 	}
-	_, _, err := authenticateByExternalBrowser(context.TODO(), sr, authenticator, application, account, user, password, timeout)
+	_, _, err := authenticateByExternalBrowser(context.Background(), sr, authenticator, application, account, user, password, timeout)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncPostAuthSAML = postAuthExternalBrowserFail
-	_, _, err = authenticateByExternalBrowser(context.TODO(), sr, authenticator, application, account, user, password, timeout)
+	_, _, err = authenticateByExternalBrowser(context.Background(), sr, authenticator, application, account, user, password, timeout)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncPostAuthSAML = postAuthExternalBrowserFailWithCode
-	_, _, err = authenticateByExternalBrowser(context.TODO(), sr, authenticator, application, account, user, password, timeout)
+	_, _, err = authenticateByExternalBrowser(context.Background(), sr, authenticator, application, account, user, password, timeout)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
@@ -128,7 +128,7 @@ func TestAuthenticationTimeout(t *testing.T) {
 		FuncPostAuthSAML: postAuthExternalBrowserError,
 		TokenAccessor:    getSimpleTokenAccessor(),
 	}
-	_, _, err := authenticateByExternalBrowser(context.TODO(), sr, authenticator, application, account, user, password, timeout)
+	_, _, err := authenticateByExternalBrowser(context.Background(), sr, authenticator, application, account, user, password, timeout)
 	if err.Error() != "authentication timed out" {
 		t.Fatal("should have timed out")
 	}
diff --git a/authokta_test.go b/authokta_test.go
index dd1cf7a..a9a4b27 100644
--- a/authokta_test.go
+++ b/authokta_test.go
@@ -64,17 +64,17 @@ func TestUnitPostAuthSAML(t *testing.T) {
 		TokenAccessor: getSimpleTokenAccessor(),
 	}
 	var err error
-	_, err = postAuthSAML(context.TODO(), sr, make(map[string]string), []byte{}, 0)
+	_, err = postAuthSAML(context.Background(), sr, make(map[string]string), []byte{}, 0)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncPost = postTestAppBadGatewayError
-	_, err = postAuthSAML(context.TODO(), sr, make(map[string]string), []byte{}, 0)
+	_, err = postAuthSAML(context.Background(), sr, make(map[string]string), []byte{}, 0)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncPost = postTestSuccessButInvalidJSON
-	_, err = postAuthSAML(context.TODO(), sr, make(map[string]string), []byte{0x12, 0x34}, 0)
+	_, err = postAuthSAML(context.Background(), sr, make(map[string]string), []byte{0x12, 0x34}, 0)
 	if err == nil {
 		t.Fatalf("should have failed to post")
 	}
@@ -86,17 +86,17 @@ func TestUnitPostAuthOKTA(t *testing.T) {
 		TokenAccessor: getSimpleTokenAccessor(),
 	}
 	var err error
-	_, err = postAuthOKTA(context.TODO(), sr, make(map[string]string), []byte{}, "hahah", 0)
+	_, err = postAuthOKTA(context.Background(), sr, make(map[string]string), []byte{}, "hahah", 0)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncPost = postTestAppBadGatewayError
-	_, err = postAuthOKTA(context.TODO(), sr, make(map[string]string), []byte{}, "hahah", 0)
+	_, err = postAuthOKTA(context.Background(), sr, make(map[string]string), []byte{}, "hahah", 0)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncPost = postTestSuccessButInvalidJSON
-	_, err = postAuthOKTA(context.TODO(), sr, make(map[string]string), []byte{0x12, 0x34}, "haha", 0)
+	_, err = postAuthOKTA(context.Background(), sr, make(map[string]string), []byte{0x12, 0x34}, "haha", 0)
 	if err == nil {
 		t.Fatal("should have failed to run post request after the renewal")
 	}
@@ -108,17 +108,17 @@ func TestUnitGetSSO(t *testing.T) {
 		TokenAccessor: getSimpleTokenAccessor(),
 	}
 	var err error
-	_, err = getSSO(context.TODO(), sr, &url.Values{}, make(map[string]string), "hahah", 0)
+	_, err = getSSO(context.Background(), sr, &url.Values{}, make(map[string]string), "hahah", 0)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncGet = getTestAppBadGatewayError
-	_, err = getSSO(context.TODO(), sr, &url.Values{}, make(map[string]string), "hahah", 0)
+	_, err = getSSO(context.Background(), sr, &url.Values{}, make(map[string]string), "hahah", 0)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncGet = getTestHTMLSuccess
-	_, err = getSSO(context.TODO(), sr, &url.Values{}, make(map[string]string), "hahah", 0)
+	_, err = getSSO(context.Background(), sr, &url.Values{}, make(map[string]string), "hahah", 0)
 	if err != nil {
 		t.Fatalf("failed to get HTML content. err: %v", err)
 	}
@@ -194,17 +194,17 @@ func TestUnitAuthenticateBySAML(t *testing.T) {
 		TokenAccessor:    getSimpleTokenAccessor(),
 	}
 	var err error
-	_, err = authenticateBySAML(context.TODO(), sr, authenticator, application, account, user, password)
+	_, err = authenticateBySAML(context.Background(), sr, authenticator, application, account, user, password)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncPostAuthSAML = postAuthSAMLAuthFail
-	_, err = authenticateBySAML(context.TODO(), sr, authenticator, application, account, user, password)
+	_, err = authenticateBySAML(context.Background(), sr, authenticator, application, account, user, password)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncPostAuthSAML = postAuthSAMLAuthSuccessButInvalidURL
-	_, err = authenticateBySAML(context.TODO(), sr, authenticator, application, account, user, password)
+	_, err = authenticateBySAML(context.Background(), sr, authenticator, application, account, user, password)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
@@ -217,23 +217,23 @@ func TestUnitAuthenticateBySAML(t *testing.T) {
 	}
 	sr.FuncPostAuthSAML = postAuthSAMLAuthSuccess
 	sr.FuncPostAuthOKTA = postAuthOKTAError
-	_, err = authenticateBySAML(context.TODO(), sr, authenticator, application, account, user, password)
+	_, err = authenticateBySAML(context.Background(), sr, authenticator, application, account, user, password)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncPostAuthOKTA = postAuthOKTASuccess
 	sr.FuncGetSSO = getSSOError
-	_, err = authenticateBySAML(context.TODO(), sr, authenticator, application, account, user, password)
+	_, err = authenticateBySAML(context.Background(), sr, authenticator, application, account, user, password)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncGetSSO = getSSOSuccessButInvalidURL
-	_, err = authenticateBySAML(context.TODO(), sr, authenticator, application, account, user, password)
+	_, err = authenticateBySAML(context.Background(), sr, authenticator, application, account, user, password)
 	if err == nil {
 		t.Fatal("should have failed.")
 	}
 	sr.FuncGetSSO = getSSOSuccess
-	_, err = authenticateBySAML(context.TODO(), sr, authenticator, application, account, user, password)
+	_, err = authenticateBySAML(context.Background(), sr, authenticator, application, account, user, password)
 	if err != nil {
 		t.Fatalf("failed. err: %v", err)
 	}
diff --git a/connection_test.go b/connection_test.go
index 0a23684..a76cdb7 100644
--- a/connection_test.go
+++ b/connection_test.go
@@ -191,7 +191,7 @@ func TestServiceName(t *testing.T) {
 
 	expectServiceName := serviceNameStub
 	for i := 0; i < 5; i++ {
-		sc.exec(context.TODO(), "", false, /* noResult */
+		sc.exec(context.Background(), "", false, /* noResult */
 			false /* isInternal */, false /* describeOnly */, nil)
 		if actualServiceName, ok := sc.cfg.Params[serviceName]; ok {
 			if *actualServiceName != expectServiceName {
diff --git a/ctx_test.go b/ctx_test.go
index f9bd5ad..9422c66 100644
--- a/ctx_test.go
+++ b/ctx_test.go
@@ -40,8 +40,8 @@ func TestCtxVal(t *testing.T) {
 
 func TestLogEntryCtx(t *testing.T) {
 	var log = logger
-	var ctx1 = context.WithValue(context.TODO(), SFSessionIDKey, "sessID1")
-	var ctx2 = context.WithValue(context.TODO(), SFSessionUserKey, "admin")
+	var ctx1 = context.WithValue(context.Background(), SFSessionIDKey, "sessID1")
+	var ctx2 = context.WithValue(context.Background(), SFSessionUserKey, "admin")
 
 	fs1 := context2Fields(ctx1)
 	fs2 := context2Fields(ctx2)
diff --git a/ocsp_test.go b/ocsp_test.go
index e2deb51..c89a7a6 100644
--- a/ocsp_test.go
+++ b/ocsp_test.go
@@ -318,7 +318,7 @@ func TestOCSPRetry(t *testing.T) {
 		body:    []byte{1, 2, 3},
 	}
 	res, b, st := retryOCSP(
-		context.TODO(),
+		context.Background(),
 		client, emptyRequest,
 		dummyOCSPHost,
 		make(map[string]string), []byte{0}, certs[len(certs)-1], 10*time.Second)
@@ -331,7 +331,7 @@ func TestOCSPRetry(t *testing.T) {
 		body:    []byte{1, 2, 3},
 	}
 	res, b, st = retryOCSP(
-		context.TODO(),
+		context.Background(),
 		client, fakeRequestFunc,
 		dummyOCSPHost,
 		make(map[string]string), []byte{0}, certs[len(certs)-1], 5*time.Second)
@@ -389,7 +389,7 @@ func TestOCSPCacheServerRetry(t *testing.T) {
 		body:    []byte{1, 2, 3},
 	}
 	res, st := checkOCSPCacheServer(
-		context.TODO(), client, fakeRequestFunc, dummyOCSPHost, 20*time.Second)
+		context.Background(), client, fakeRequestFunc, dummyOCSPHost, 20*time.Second)
 	if st.err == nil {
 		t.Errorf("should fail: %v", res)
 	}
@@ -399,7 +399,7 @@ func TestOCSPCacheServerRetry(t *testing.T) {
 		body:    []byte{1, 2, 3},
 	}
 	res, st = checkOCSPCacheServer(
-		context.TODO(), client, fakeRequestFunc, dummyOCSPHost, 10*time.Second)
+		context.Background(), client, fakeRequestFunc, dummyOCSPHost, 10*time.Second)
 	if st.err == nil {
 		t.Errorf("should fail: %v", res)
 	}
diff --git a/retry_test.go b/retry_test.go
index ea9ee18..397da9e 100644
--- a/retry_test.go
+++ b/retry_test.go
@@ -225,7 +225,7 @@ func TestRetryQuerySuccess(t *testing.T) {
 	if err != nil {
 		t.Fatal("failed to parse the test URL")
 	}
-	_, err = newRetryHTTP(context.TODO(),
+	_, err = newRetryHTTP(context.Background(),
 		client,
 		emptyRequest, urlPtr, make(map[string]string), 60*time.Second, constTimeProvider(123456), &Config{IncludeRetryReason: ConfigBoolTrue}).doPost().setBody([]byte{0}).execute()
 	if err != nil {
@@ -274,7 +274,7 @@ func TestRetryQuerySuccessWithRetryReasonDisabled(t *testing.T) {
 	if err != nil {
 		t.Fatal("failed to parse the test URL")
 	}
-	_, err = newRetryHTTP(context.TODO(),
+	_, err = newRetryHTTP(context.Background(),
 		client,
 		emptyRequest, urlPtr, make(map[string]string), 60*time.Second, constTimeProvider(123456), &Config{IncludeRetryReason: ConfigBoolFalse}).doPost().setBody([]byte{0}).execute()
 	if err != nil {
@@ -320,7 +320,7 @@ func TestRetryQuerySuccessWithTimeout(t *testing.T) {
 	if err != nil {
 		t.Fatal("failed to parse the test URL")
 	}
-	_, err = newRetryHTTP(context.TODO(),
+	_, err = newRetryHTTP(context.Background(),
 		client,
 		emptyRequest, urlPtr, make(map[string]string), 60*time.Second, constTimeProvider(123456), nil).doPost().setBody([]byte{0}).execute()
 	if err != nil {
@@ -350,7 +350,7 @@ func TestRetryQueryFail(t *testing.T) {
 	if err != nil {
 		t.Fatal("failed to parse the test URL")
 	}
-	_, err = newRetryHTTP(context.TODO(),
+	_, err = newRetryHTTP(context.Background(),
 		client,
 		emptyRequest, urlPtr, make(map[string]string), 60*time.Second, defaultTimeProvider, nil).doPost().setBody([]byte{0}).execute()
 	if err == nil {
@@ -396,7 +396,7 @@ func TestRetryLoginRequest(t *testing.T) {
 	if err != nil {
 		t.Fatal("failed to parse the test URL")
 	}
-	_, err = newRetryHTTP(context.TODO(),
+	_, err = newRetryHTTP(context.Background(),
 		client,
 		emptyRequest, urlPtr, make(map[string]string), 60*time.Second, defaultTimeProvider, nil).doPost().setBody([]byte{0}).execute()
 	if err != nil {
@@ -416,7 +416,7 @@ func TestRetryLoginRequest(t *testing.T) {
 		success: false,
 		timeout: true,
 	}
-	_, err = newRetryHTTP(context.TODO(),
+	_, err = newRetryHTTP(context.Background(),
 		client,
 		emptyRequest, urlPtr, make(map[string]string), 10*time.Second, defaultTimeProvider, nil).doPost().setBody([]byte{0}).execute()
 	if err == nil {
@@ -447,7 +447,7 @@ func TestRetryAuthLoginRequest(t *testing.T) {
 		execID++
 		return []byte(fmt.Sprintf("execID: %d", execID)), nil
 	}
-	_, err = newRetryHTTP(context.TODO(),
+	_, err = newRetryHTTP(context.Background(),
 		client,
 		http.NewRequest, urlPtr, make(map[string]string), 60*time.Second, defaultTimeProvider, nil).doPost().setBodyCreator(bodyCreator).execute()
 	if err != nil {
@@ -468,7 +468,7 @@ func TestLoginRetry429(t *testing.T) {
 	if err != nil {
 		t.Fatal("failed to parse the test URL")
 	}
-	_, err = newRetryHTTP(context.TODO(),
+	_, err = newRetryHTTP(context.Background(),
 		client,
 		emptyRequest, urlPtr, make(map[string]string), 60*time.Second, defaultTimeProvider, nil).doRaise4XX(true).doPost().setBody([]byte{0}).execute() // enable doRaise4XXX
 	if err != nil {