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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
package app
import (
"path/filepath"
"testing"
"github.com/isacikgoz/gitbatch/internal/git"
"github.com/stretchr/testify/require"
)
func TestGenerateDirectories(t *testing.T) {
th := git.InitTestRepositoryFromLocal(t)
defer th.CleanUp(t)
var tests = []struct {
inp1 []string
inp2 int
expected []string
}{
{[]string{th.RepoPath}, 1, []string{th.BasicRepoPath(), th.DirtyRepoPath()}},
{[]string{th.RepoPath}, 2, []string{th.BasicRepoPath(), th.DirtyRepoPath()}}, // maybe move one repo to a sub folder
}
for _, test := range tests {
output := generateDirectories(test.inp1, test.inp2)
require.ElementsMatch(t, output, test.expected)
}
}
func TestWalkRecursive(t *testing.T) {
th := git.InitTestRepositoryFromLocal(t)
defer th.CleanUp(t)
var tests = []struct {
inp1 []string
inp2 []string
exp1 []string
exp2 []string
}{
{
[]string{th.RepoPath},
[]string{""},
[]string{filepath.Join(th.RepoPath, ".git"), filepath.Join(th.RepoPath, ".gitmodules"), th.NonRepoPath()},
[]string{"", th.BasicRepoPath(), th.DirtyRepoPath()},
},
}
for _, test := range tests {
out1, out2 := walkRecursive(test.inp1, test.inp2)
require.ElementsMatch(t, out1, test.exp1)
require.ElementsMatch(t, out2, test.exp2)
}
}
func TestSeparateDirectories(t *testing.T) {
th := git.InitTestRepositoryFromLocal(t)
defer th.CleanUp(t)
var tests = []struct {
input string
exp1 []string
exp2 []string
}{
{
"",
nil,
nil,
},
{
th.RepoPath,
[]string{filepath.Join(th.RepoPath, ".git"), filepath.Join(th.RepoPath, ".gitmodules"), th.NonRepoPath()},
[]string{th.BasicRepoPath(), th.DirtyRepoPath()},
},
}
for _, test := range tests {
out1, out2, err := separateDirectories(test.input)
require.NoError(t, err)
require.ElementsMatch(t, out1, test.exp1)
require.ElementsMatch(t, out2, test.exp2)
}
}
|