Debian Codegraph @

internal/app/files_test.go

raw symbols SCIP
1 package app
2
3 import (
4 "path/filepath"
5 "testing"
6
7 "github.com/isacikgoz/gitbatch/internal/git"
8 "github.com/stretchr/testify/require"
9 )
10
11 func TestGenerateDirectories(t *testing.T) {
12 th := git.InitTestRepositoryFromLocal(t)
13 defer th.CleanUp(t)
14
15 var tests = []struct {
16 inp1 []string
17 inp2 int
18 expected []string
19 }{
20 {[]string{th.RepoPath}, 1, []string{th.BasicRepoPath(), th.DirtyRepoPath()}},
21 {[]string{th.RepoPath}, 2, []string{th.BasicRepoPath(), th.DirtyRepoPath()}}, // maybe move one repo to a sub folder
22 }
23 for _, test := range tests {
24 output := generateDirectories(test.inp1, test.inp2)
25 require.ElementsMatch(t, output, test.expected)
26 }
27 }
28
29 func TestWalkRecursive(t *testing.T) {
30 th := git.InitTestRepositoryFromLocal(t)
31 defer th.CleanUp(t)
32
33 var tests = []struct {
34 inp1 []string
35 inp2 []string
36 exp1 []string
37 exp2 []string
38 }{
39 {
40 []string{th.RepoPath},
41 []string{""},
42 []string{filepath.Join(th.RepoPath, ".git"), filepath.Join(th.RepoPath, ".gitmodules"), th.NonRepoPath()},
43 []string{"", th.BasicRepoPath(), th.DirtyRepoPath()},
44 },
45 }
46 for _, test := range tests {
47 out1, out2 := walkRecursive(test.inp1, test.inp2)
48 require.ElementsMatch(t, out1, test.exp1)
49 require.ElementsMatch(t, out2, test.exp2)
50 }
51 }
52
53 func TestSeparateDirectories(t *testing.T) {
54 th := git.InitTestRepositoryFromLocal(t)
55 defer th.CleanUp(t)
56
57 var tests = []struct {
58 input string
59 exp1 []string
60 exp2 []string
61 }{
62 {
63 "",
64 nil,
65 nil,
66 },
67 {
68 th.RepoPath,
69 []string{filepath.Join(th.RepoPath, ".git"), filepath.Join(th.RepoPath, ".gitmodules"), th.NonRepoPath()},
70 []string{th.BasicRepoPath(), th.DirtyRepoPath()},
71 },
72 }
73 for _, test := range tests {
74 out1, out2, err := separateDirectories(test.input)
75 require.NoError(t, err)
76 require.ElementsMatch(t, out1, test.exp1)
77 require.ElementsMatch(t, out2, test.exp2)
78 }
79 }