2020-01-31 23:58:10 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2020-02-10 13:41:58 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-01-31 23:58:10 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-02-01 00:41:38 +00:00
|
|
|
func absPaths(files []string) []string {
|
2020-01-31 23:58:10 +00:00
|
|
|
var abs []string
|
|
|
|
for _, f := range files {
|
|
|
|
absPath, _ := filepath.Abs("../testdata/list/" + f)
|
|
|
|
abs = append(abs, absPath)
|
|
|
|
}
|
|
|
|
return abs
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListTestFiles(t *testing.T) {
|
|
|
|
require.Equal(t,
|
2020-02-01 00:41:38 +00:00
|
|
|
absPaths([]string{"sum/private_test.go", "sum/public_test.go"}),
|
2020-01-31 23:58:10 +00:00
|
|
|
listTestFiles("../testdata/list"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProtectedFiles(t *testing.T) {
|
|
|
|
require.Equal(t,
|
|
|
|
absPaths([]string{"sum/dontchange.go"}),
|
|
|
|
listProtectedFiles("../testdata/list"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrivateFiles(t *testing.T) {
|
|
|
|
require.Equal(t,
|
2020-02-01 00:41:38 +00:00
|
|
|
absPaths([]string{"sum/private_test.go", "sum/solution.go"}),
|
|
|
|
listPrivateFiles("../testdata/list"))
|
|
|
|
}
|
2020-02-10 13:41:58 +00:00
|
|
|
|
|
|
|
func TestListPackages(t *testing.T) {
|
|
|
|
binaries, tests := listTestsAndBinaries("../testdata/pkgfind/task", []string{"-tags", "private"})
|
|
|
|
|
|
|
|
assert.Equal(t, binaries, map[string]struct{}{
|
|
|
|
"gitlab.com/slon/shad-go/task/cmd/tool": {},
|
|
|
|
"gitlab.com/slon/shad-go/task/cmd/tool_with_test": {},
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.Equal(t, tests, map[string]struct{}{
|
|
|
|
"gitlab.com/slon/shad-go/task/cmd/tool_with_test": {},
|
|
|
|
"gitlab.com/slon/shad-go/task/pkg/a": {},
|
|
|
|
"gitlab.com/slon/shad-go/task/pkg/c": {},
|
|
|
|
})
|
|
|
|
}
|