MCPcopy Index your code
hub / github.com/docker/cli / TestUseDefaultWithoutConfigFile

Function TestUseDefaultWithoutConfigFile

cli/command/context/use_test.go:54–82  ·  view source on GitHub ↗

TestUseDefaultWithoutConfigFile verifies that the CLI does not create the default config file and directory when using the default context.

(t *testing.T)

Source from the content-addressed store, hash-verified

52// TestUseDefaultWithoutConfigFile verifies that the CLI does not create
53// the default config file and directory when using the default context.
54func TestUseDefaultWithoutConfigFile(t *testing.T) {
55 // We must use a temporary home-directory, because this test covers
56 // the _default_ configuration file. If we specify a custom configuration
57 // file, the CLI produces an error if the file doesn't exist.
58 tmpHomeDir := t.TempDir()
59 if runtime.GOOS == "windows" {
60 t.Setenv("USERPROFILE", tmpHomeDir)
61 } else {
62 t.Setenv("HOME", tmpHomeDir)
63 }
64 configDir := filepath.Join(tmpHomeDir, ".docker")
65 configFilePath := filepath.Join(configDir, "config.json")
66
67 // Verify config-dir and -file don't exist before
68 _, err := os.Stat(configDir)
69 assert.Check(t, errors.Is(err, os.ErrNotExist))
70 _, err = os.Stat(configFilePath)
71 assert.Check(t, errors.Is(err, os.ErrNotExist))
72
73 cli, err := command.NewDockerCli(command.WithCombinedStreams(io.Discard))
74 assert.NilError(t, err)
75 assert.NilError(t, newUseCommand(cli).RunE(nil, []string{"default"}))
76
77 // Verify config-dir and -file don't exist after
78 _, err = os.Stat(configDir)
79 assert.Check(t, errors.Is(err, os.ErrNotExist))
80 _, err = os.Stat(configFilePath)
81 assert.Check(t, errors.Is(err, os.ErrNotExist))
82}
83
84func TestUseHostOverride(t *testing.T) {
85 t.Setenv("DOCKER_HOST", "tcp://ed:2375/")

Callers

nothing calls this directly

Calls 1

newUseCommandFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…