Skip to content

Commit b9bdf6f

Browse files
Fix failing tests due to wrong context
1 parent 0294a93 commit b9bdf6f

3 files changed

Lines changed: 5 additions & 14 deletions

File tree

cmd/auth/logout_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package auth
22

33
import (
4-
"context"
54
"os"
65
"path/filepath"
76
"testing"
@@ -161,7 +160,7 @@ func TestLogout(t *testing.T) {
161160

162161
for _, tc := range cases {
163162
t.Run(tc.name, func(t *testing.T) {
164-
ctx := cmdio.MockDiscard(context.Background())
163+
ctx := cmdio.MockDiscard(t.Context())
165164
configPath := writeTempConfig(t, logoutTestConfig)
166165
t.Setenv("DATABRICKS_CONFIG_FILE", configPath)
167166

@@ -204,7 +203,7 @@ func TestLogout(t *testing.T) {
204203
}
205204

206205
func TestLogoutNoTokens(t *testing.T) {
207-
ctx := cmdio.MockDiscard(context.Background())
206+
ctx := cmdio.MockDiscard(t.Context())
208207
configPath := writeTempConfig(t, logoutTestConfig)
209208
t.Setenv("DATABRICKS_CONFIG_FILE", configPath)
210209

@@ -228,7 +227,7 @@ func TestLogoutNoTokens(t *testing.T) {
228227
}
229228

230229
func TestLogoutNoTokensWithDelete(t *testing.T) {
231-
ctx := cmdio.MockDiscard(context.Background())
230+
ctx := cmdio.MockDiscard(t.Context())
232231
configPath := writeTempConfig(t, logoutTestConfig)
233232
t.Setenv("DATABRICKS_CONFIG_FILE", configPath)
234233

libs/databrickscfg/ops_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ host = https://only.cloud.databricks.com
341341

342342
for _, tc := range cases {
343343
t.Run(tc.name, func(t *testing.T) {
344-
ctx := context.Background()
344+
ctx := t.Context()
345345
path := filepath.Join(t.TempDir(), ".databrickscfg")
346346
require.NoError(t, os.WriteFile(path, []byte(tc.seedConfig), fileMode))
347347

@@ -367,7 +367,7 @@ host = https://only.cloud.databricks.com
367367
}
368368

369369
func TestDeleteProfile_NotFound(t *testing.T) {
370-
ctx := context.Background()
370+
ctx := t.Context()
371371
path := filepath.Join(t.TempDir(), ".databrickscfg")
372372
require.NoError(t, os.WriteFile(path, []byte(""), fileMode))
373373

libs/gorules/rule_context_background.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@ package gorules
22

33
import "github.com/quasilyte/go-ruleguard/dsl"
44

5-
<<<<<<< HEAD
65
// NoContextBackground detects context.Background() outside of main.go files.
76
func NoContextBackground(m dsl.Matcher) {
87
m.Match(`context.Background()`).
98
Where(!m.File().Name.Matches(`^main\.go$`)).
109
Report(`Do not use context.Background(); use t.Context() in tests or pass context from caller`)
11-
=======
12-
// UseTestContext detects context.Background() in test files and suggests using t.Context().
13-
func UseTestContext(m dsl.Matcher) {
14-
m.Match(`context.Background()`).
15-
Where(m.File().Name.Matches(`_test\.go$`)).
16-
Report(`Use t.Context() or b.Context() in tests instead of context.Background()`)
17-
>>>>>>> 47d9694f3 (Use t.Context() instead of context.Background() in tests (#4655))
1810
}

0 commit comments

Comments
 (0)