[gitfame] Sort tests.
This commit is contained in:
parent
c7486767c2
commit
72498e46ac
1 changed files with 33 additions and 9 deletions
|
@ -6,6 +6,8 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -34,17 +36,12 @@ func TestGitFame(t *testing.T) {
|
||||||
|
|
||||||
bundlesDir := path.Join("./testdata", "bundles")
|
bundlesDir := path.Join("./testdata", "bundles")
|
||||||
testsDir := path.Join("./testdata", "tests")
|
testsDir := path.Join("./testdata", "tests")
|
||||||
files, err := ioutil.ReadDir(testsDir)
|
testDirs := ListTestDirs(t, testsDir)
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
for _, f := range files {
|
for _, dir := range testDirs {
|
||||||
if !f.IsDir() {
|
tc := ReadTestCase(t, filepath.Join(testsDir, dir))
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
tc := ReadTestCase(t, filepath.Join(testsDir, f.Name()))
|
t.Run(dir+"/"+tc.Name, func(t *testing.T) {
|
||||||
|
|
||||||
t.Run(f.Name()+"/"+tc.Name, func(t *testing.T) {
|
|
||||||
dir, err := ioutil.TempDir("", "gitfame-")
|
dir, err := ioutil.TempDir("", "gitfame-")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer func() { _ = os.RemoveAll(dir) }()
|
defer func() { _ = os.RemoveAll(dir) }()
|
||||||
|
@ -70,6 +67,33 @@ func TestGitFame(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ListTestDirs(t *testing.T, path string) []string {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
files, err := ioutil.ReadDir(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var names []string
|
||||||
|
for _, f := range files {
|
||||||
|
if !f.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
names = append(names, f.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
toInt := func(name string) int {
|
||||||
|
i, err := strconv.Atoi(name)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(names, func(i, j int) bool {
|
||||||
|
return toInt(names[i]) < toInt(names[j])
|
||||||
|
})
|
||||||
|
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
type TestCase struct {
|
type TestCase struct {
|
||||||
*TestDescription
|
*TestDescription
|
||||||
Expected []byte
|
Expected []byte
|
||||||
|
|
Loading…
Reference in a new issue