shad-go/tools/testtool/commands/list_test.go
Fedor Korotkiy 0de2390008 Squashed commit of the following:
commit 347ba11cfe4a49bff6fc29063b49416d90525e52
Author: Fedor Korotkiy <prime@yandex-team.ru>
Date:   Sat Feb 8 22:44:26 2020 +0300

    Sandboxed test execution.

commit c5c9557dd59c54971a78d424ec118655f6b2005c
Author: Fedor Korotkiy <prime@yandex-team.ru>
Date:   Sat Feb 8 21:13:13 2020 +0300

    Fix paths used during testing.

commit 1ba21eb0aad08f543c6a99bfd927721207943abb
Author: Fedor Korotkiy <prime@yandex-team.ru>
Date:   Sat Feb 8 20:56:32 2020 +0300

    Helper for process sandboxing

commit 54f0aa11156c1d2c998a060b60be7af8666d5da4
Author: Fedor Korotkiy <prime@yandex-team.ru>
Date:   Sat Feb 8 20:10:56 2020 +0300

    Package list helper.
2020-02-10 16:41:58 +03:00

51 lines
1.3 KiB
Go

package commands
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func absPaths(files []string) []string {
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,
absPaths([]string{"sum/private_test.go", "sum/public_test.go"}),
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,
absPaths([]string{"sum/private_test.go", "sum/solution.go"}),
listPrivateFiles("../testdata/list"))
}
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": {},
})
}