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

Function TestValidateOutputPath

cli/command/utils_test.go:13–45  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestValidateOutputPath(t *testing.T) {
14 basedir := t.TempDir()
15 dir := filepath.Join(basedir, "dir")
16 notexist := filepath.Join(basedir, "notexist")
17 err := os.MkdirAll(dir, 0o755)
18 assert.NilError(t, err)
19 file := filepath.Join(dir, "file")
20 err = os.WriteFile(file, []byte("hi"), 0o644)
21 assert.NilError(t, err)
22 testcases := []struct {
23 path string
24 err error
25 }{
26 {basedir, nil},
27 {file, nil},
28 {dir, nil},
29 {dir + string(os.PathSeparator), nil},
30 {notexist, nil},
31 {notexist + string(os.PathSeparator), nil},
32 {filepath.Join(notexist, "file"), errors.New("does not exist")},
33 }
34
35 for _, testcase := range testcases {
36 t.Run(testcase.path, func(t *testing.T) {
37 err := command.ValidateOutputPath(testcase.path)
38 if testcase.err == nil {
39 assert.NilError(t, err)
40 } else {
41 assert.ErrorContains(t, err, testcase.err.Error())
42 }
43 })
44 }
45}

Callers

nothing calls this directly

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…