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

Function TestUseHostOverride

cli/command/context/use_test.go:84–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

82}
83
84func TestUseHostOverride(t *testing.T) {
85 t.Setenv("DOCKER_HOST", "tcp://ed:2375/")
86
87 configDir := t.TempDir()
88 configFilePath := filepath.Join(configDir, "config.json")
89 testCfg := configfile.New(configFilePath)
90 cli := makeFakeCli(t, withCliConfig(testCfg))
91 err := runCreate(cli, "test", createOptions{
92 endpoint: map[string]string{},
93 })
94 assert.NilError(t, err)
95
96 cli.ResetOutputBuffers()
97 err = newUseCommand(cli).RunE(nil, []string{"test"})
98 assert.NilError(t, err)
99 assert.Assert(t, is.Contains(
100 cli.ErrBuffer().String(),
101 `Warning: DOCKER_HOST environment variable overrides the active context.`,
102 ))
103 assert.Assert(t, is.Contains(cli.ErrBuffer().String(), `Current context is now "test"`))
104 assert.Equal(t, cli.OutBuffer().String(), "test\n")
105
106 // setting DOCKER_HOST with the default context should not print a warning
107 cli.ResetOutputBuffers()
108 err = newUseCommand(cli).RunE(nil, []string{"default"})
109 assert.NilError(t, err)
110 assert.Assert(t, is.Contains(cli.ErrBuffer().String(), `Current context is now "default"`))
111 assert.Equal(t, cli.OutBuffer().String(), "default\n")
112}
113
114// An empty DOCKER_HOST used to break the 'context use' flow.
115// So we have a test with fewer fakes that tests this flow holistically.

Callers

nothing calls this directly

Calls 9

makeFakeCliFunction · 0.85
withCliConfigFunction · 0.85
newUseCommandFunction · 0.85
ContainsMethod · 0.80
runCreateFunction · 0.70
StringMethod · 0.65
ResetOutputBuffersMethod · 0.45
ErrBufferMethod · 0.45
OutBufferMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…