forked from databricks/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
50 lines (46 loc) · 1.24 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"io/fs"
"path/filepath"
"testing"
"github.com/databricks/cli/cmd"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"golang.org/x/mod/module"
)
func TestCommandsDontUseUnderscoreInName(t *testing.T) {
// We use underscore as separator between commands in logs
// so need to enforce that no command uses it in its name.
//
// This test lives in the main package because this is where
// all commands are imported.
//
queue := []*cobra.Command{cmd.New(context.Background())}
for len(queue) > 0 {
cmd := queue[0]
assert.NotContains(t, cmd.Name(), "_")
queue = append(queue[1:], cmd.Commands()...)
}
}
func TestFilePath(t *testing.T) {
// To import this repository as a library, all files must match the
// file path constraints made by Go. This test ensures that all files
// in the repository have a valid file path.
//
// See https://github.com/databricks/cli/issues/1629
//
err := filepath.WalkDir(".", func(path string, _ fs.DirEntry, err error) error {
switch path {
case ".":
return nil
case ".git":
return filepath.SkipDir
}
if assert.NoError(t, err) {
assert.NoError(t, module.CheckFilePath(filepath.ToSlash(path)))
}
return nil
})
assert.NoError(t, err)
}