TestUseDefaultWithoutConfigFile verifies that the CLI does not create the default config file and directory when using the default context.
(t *testing.T)
| 52 | // TestUseDefaultWithoutConfigFile verifies that the CLI does not create |
| 53 | // the default config file and directory when using the default context. |
| 54 | func 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 | |
| 84 | func TestUseHostOverride(t *testing.T) { |
| 85 | t.Setenv("DOCKER_HOST", "tcp://ed:2375/") |
nothing calls this directly
no test coverage detected
searching dependent graphs…