(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…