2023-02-03 15:47:33 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-09-11 08:18:43 +00:00
|
|
|
"context"
|
2024-08-12 14:20:04 +00:00
|
|
|
"io/fs"
|
|
|
|
"path/filepath"
|
2023-02-03 15:47:33 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
"github.com/databricks/cli/cmd"
|
2023-02-03 15:47:33 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-08-12 14:20:04 +00:00
|
|
|
"golang.org/x/mod/module"
|
2023-02-03 15:47:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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.
|
|
|
|
//
|
2023-09-11 08:18:43 +00:00
|
|
|
queue := []*cobra.Command{cmd.New(context.Background())}
|
2023-02-03 15:47:33 +00:00
|
|
|
for len(queue) > 0 {
|
|
|
|
cmd := queue[0]
|
|
|
|
assert.NotContains(t, cmd.Name(), "_")
|
|
|
|
queue = append(queue[1:], cmd.Commands()...)
|
|
|
|
}
|
|
|
|
}
|
2024-08-12 14:20:04 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|