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

Function TestUse

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

Source from the content-addressed store, hash-verified

19)
20
21func TestUse(t *testing.T) {
22 configDir := t.TempDir()
23 configFilePath := filepath.Join(configDir, "config.json")
24 testCfg := configfile.New(configFilePath)
25 cli := makeFakeCli(t, withCliConfig(testCfg))
26 err := runCreate(cli, "test", createOptions{
27 endpoint: map[string]string{},
28 })
29 assert.NilError(t, err)
30 assert.NilError(t, newUseCommand(cli).RunE(nil, []string{"test"}))
31 reloadedConfig, err := config.Load(configDir)
32 assert.NilError(t, err)
33 assert.Equal(t, "test", reloadedConfig.CurrentContext)
34
35 // switch back to default
36 cli.OutBuffer().Reset()
37 cli.ErrBuffer().Reset()
38 assert.NilError(t, newUseCommand(cli).RunE(nil, []string{"default"}))
39 reloadedConfig, err = config.Load(configDir)
40 assert.NilError(t, err)
41 assert.Equal(t, "", reloadedConfig.CurrentContext)
42 assert.Equal(t, "default\n", cli.OutBuffer().String())
43 assert.Equal(t, "Current context is now \"default\"\n", cli.ErrBuffer().String())
44}
45
46func TestUseNoExist(t *testing.T) {
47 cli := makeFakeCli(t)

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…