Skip to content

Commit b72f644

Browse files
committed
Replace context.Background() with t.Context() in tests
Fixes gocritic lint rule after the t.Context() migration on main.
1 parent 51c780a commit b72f644

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

cmd/auth/login_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ func TestHasNoProfiles_FreshMachine(t *testing.T) {
262262
// On a fresh machine there is no config file. LoadProfiles returns
263263
// ErrNoConfiguration. hasNoProfiles must treat this as "no profiles"
264264
// (return true), not as an error (return false).
265-
ctx := context.Background()
265+
ctx := t.Context()
266266
t.Setenv("DATABRICKS_CONFIG_FILE", filepath.Join(t.TempDir(), "nonexistent"))
267267
assert.True(t, hasNoProfiles(ctx, profile.DefaultProfiler))
268268
}
269269

270270
func TestHasNoProfiles_EmptyFile(t *testing.T) {
271-
ctx := context.Background()
271+
ctx := t.Context()
272272
dir := t.TempDir()
273273
configFile := filepath.Join(dir, ".databrickscfg")
274274
require.NoError(t, os.WriteFile(configFile, []byte(""), 0o600))
@@ -277,7 +277,7 @@ func TestHasNoProfiles_EmptyFile(t *testing.T) {
277277
}
278278

279279
func TestHasNoProfiles_WithExistingProfile(t *testing.T) {
280-
ctx := context.Background()
280+
ctx := t.Context()
281281
dir := t.TempDir()
282282
configFile := filepath.Join(dir, ".databrickscfg")
283283
require.NoError(t, os.WriteFile(configFile, []byte("[p1]\nhost = https://abc\n"), 0o600))

cmd/auth/switch_test.go

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

33
import (
4-
"context"
54
"fmt"
65
"os"
76
"path/filepath"
@@ -15,7 +14,7 @@ import (
1514
)
1615

1716
func TestSwitchCommand_WithProfileFlag(t *testing.T) {
18-
ctx := context.Background()
17+
ctx := t.Context()
1918
dir := t.TempDir()
2019
configFile := filepath.Join(dir, ".databrickscfg")
2120

@@ -45,7 +44,7 @@ func TestSwitchCommand_WithProfileFlag(t *testing.T) {
4544
}
4645

4746
func TestSwitchCommand_ProfileNotFound(t *testing.T) {
48-
ctx := context.Background()
47+
ctx := t.Context()
4948
dir := t.TempDir()
5049
configFile := filepath.Join(dir, ".databrickscfg")
5150

@@ -71,7 +70,7 @@ func TestSwitchCommand_ProfileNotFound(t *testing.T) {
7170
}
7271

7372
func TestSwitchCommand_NonInteractiveNoProfile(t *testing.T) {
74-
ctx := context.Background()
73+
ctx := t.Context()
7574
dir := t.TempDir()
7675
configFile := filepath.Join(dir, ".databrickscfg")
7776

@@ -97,7 +96,7 @@ func TestSwitchCommand_NonInteractiveNoProfile(t *testing.T) {
9796
}
9897

9998
func TestSwitchCommand_WritesSettingsSection(t *testing.T) {
100-
ctx := context.Background()
99+
ctx := t.Context()
101100
dir := t.TempDir()
102101
configFile := filepath.Join(dir, ".databrickscfg")
103102

cmd/root/auth_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ token = flag-token
385385
t.Setenv("DATABRICKS_CONFIG_PROFILE", tc.envProfile)
386386
}
387387

388-
ctx := cmdio.MockDiscard(context.Background())
388+
ctx := cmdio.MockDiscard(t.Context())
389389
ctx = SkipLoadBundle(ctx)
390390
cmd := New(ctx)
391391

@@ -422,7 +422,7 @@ token = named-token
422422

423423
t.Setenv("DATABRICKS_CONFIG_FILE", configFile)
424424

425-
ctx := cmdio.MockDiscard(context.Background())
425+
ctx := cmdio.MockDiscard(t.Context())
426426
ctx = SkipLoadBundle(ctx)
427427
cmd := New(ctx)
428428

0 commit comments

Comments
 (0)