Skip to content

Commit b82e30e

Browse files
committed
cli/command/registry: remove uses of "gotest.tools/v3/fs"
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent e30ce84 commit b82e30e

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

cli/command/registry/login_test.go

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/creack/pty"
13+
"github.com/docker/cli/cli/config/configfile"
1314
configtypes "github.com/docker/cli/cli/config/types"
1415
"github.com/docker/cli/cli/streams"
1516
"github.com/docker/cli/internal/prompt"
@@ -19,7 +20,6 @@ import (
1920
"github.com/moby/moby/client"
2021
"gotest.tools/v3/assert"
2122
is "gotest.tools/v3/assert/cmp"
22-
"gotest.tools/v3/fs"
2323
)
2424

2525
const (
@@ -71,8 +71,9 @@ func TestLoginWithCredStoreCreds(t *testing.T) {
7171
},
7272
}
7373
ctx := context.Background()
74+
tmpDir := t.TempDir()
7475
cli := test.NewFakeCli(&fakeClient{})
75-
cli.ConfigFile().Filename = filepath.Join(t.TempDir(), "config.json")
76+
cli.SetConfigFile(configfile.New(filepath.Join(tmpDir, "config.json")))
7677
for _, tc := range testCases {
7778
_, err := loginWithStoredCredentials(ctx, cli, tc.inputAuthConfig)
7879
if tc.expectedErrMsg != "" {
@@ -290,16 +291,15 @@ func TestRunLogin(t *testing.T) {
290291

291292
for _, tc := range testCases {
292293
t.Run(tc.doc, func(t *testing.T) {
293-
tmpFile := fs.NewFile(t, "test-run-login")
294-
defer tmpFile.Remove()
294+
tmpDir := t.TempDir()
295+
cfg := configfile.New(filepath.Join(tmpDir, "config.json"))
295296
cli := test.NewFakeCli(&fakeClient{})
296-
configfile := cli.ConfigFile()
297-
configfile.Filename = tmpFile.Path()
297+
cli.SetConfigFile(cfg)
298298

299299
for _, priorCred := range tc.priorCredentials {
300-
assert.NilError(t, configfile.GetCredentialsStore(priorCred.ServerAddress).Store(priorCred))
300+
assert.NilError(t, cfg.GetCredentialsStore(priorCred.ServerAddress).Store(priorCred))
301301
}
302-
storedCreds, err := configfile.GetAllCredentials()
302+
storedCreds, err := cfg.GetAllCredentials()
303303
assert.NilError(t, err)
304304
assert.DeepEqual(t, storedCreds, tc.priorCredentials)
305305

@@ -310,7 +310,7 @@ func TestRunLogin(t *testing.T) {
310310
}
311311
assert.NilError(t, loginErr)
312312

313-
outputCreds, err := configfile.GetAllCredentials()
313+
outputCreds, err := cfg.GetAllCredentials()
314314
assert.Check(t, err)
315315
assert.DeepEqual(t, outputCreds, tc.expectedCredentials)
316316
})
@@ -356,11 +356,10 @@ func TestLoginNonInteractive(t *testing.T) {
356356
for _, registryAddr := range registries {
357357
for _, tc := range testCases {
358358
t.Run(tc.doc, func(t *testing.T) {
359-
tmpFile := fs.NewFile(t, "test-run-login")
360-
defer tmpFile.Remove()
359+
tmpDir := t.TempDir()
360+
cfg := configfile.New(filepath.Join(tmpDir, "config.json"))
361361
cli := test.NewFakeCli(&fakeClient{})
362-
cfg := cli.ConfigFile()
363-
cfg.Filename = tmpFile.Path()
362+
cli.SetConfigFile(cfg)
364363
options := loginOptions{
365364
serverAddress: registryAddr,
366365
}
@@ -419,11 +418,10 @@ func TestLoginNonInteractive(t *testing.T) {
419418
for _, registryAddr := range registries {
420419
for _, tc := range testCases {
421420
t.Run(tc.doc, func(t *testing.T) {
422-
tmpFile := fs.NewFile(t, "test-run-login")
423-
defer tmpFile.Remove()
421+
tmpDir := t.TempDir()
422+
cfg := configfile.New(filepath.Join(tmpDir, "config.json"))
424423
cli := test.NewFakeCli(&fakeClient{})
425-
cfg := cli.ConfigFile()
426-
cfg.Filename = tmpFile.Path()
424+
cli.SetConfigFile(cfg)
427425
serverAddress := registryAddr
428426
if serverAddress == "" {
429427
serverAddress = "https://index.docker.io/v1/"
@@ -465,17 +463,15 @@ func TestLoginTermination(t *testing.T) {
465463
_ = p.Close()
466464
})
467465

466+
tmpDir := t.TempDir()
467+
cfg := configfile.New(filepath.Join(tmpDir, "config.json"))
468468
cli := test.NewFakeCli(&fakeClient{}, func(fc *test.FakeCli) {
469469
fc.SetOut(streams.NewOut(tty))
470470
fc.SetIn(streams.NewIn(tty))
471471
})
472-
tmpFile := fs.NewFile(t, "test-login-termination")
473-
defer tmpFile.Remove()
472+
cli.SetConfigFile(cfg)
474473

475-
configFile := cli.ConfigFile()
476-
configFile.Filename = tmpFile.Path()
477-
478-
ctx, cancel := context.WithCancel(context.Background())
474+
ctx, cancel := context.WithCancel(t.Context())
479475
t.Cleanup(cancel)
480476

481477
runErr := make(chan error)

0 commit comments

Comments
 (0)