-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathscan_test.go
70 lines (64 loc) · 1.41 KB
/
scan_test.go
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
package main
import (
"os"
"path"
"slices"
"testing"
)
func TestScanGitFolders(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatalf("failed to get working directory: %v", err)
}
test := []struct {
Name string
Root string
Want []string
ExpectErr bool
}{
{
Name: "5 expected repos",
Root: path.Join(wd, "test_data"),
Want: []string{
path.Join(wd, "test_data", "project_1"),
path.Join(wd, "test_data", "project_2"),
path.Join(wd, "test_data", "project_3"),
path.Join(wd, "test_data", "project_that_has_future_commits"),
path.Join(wd, "test_data", "project_by_another_contributor"),
},
},
{
Name: "no expected repos",
Root: path.Join(wd, ".github"),
Want: []string{},
},
{
Name: "path does not exist",
Root: path.Join(wd, "does_not_exist"),
Want: []string{},
ExpectErr: true,
},
}
for _, tt := range test {
t.Run(tt.Name, func(t *testing.T) {
got, err := scanGitFolders(tt.Root)
if tt.ExpectErr {
if err == nil {
t.Fatalf("expected error, got nil")
}
return
}
if err != nil {
t.Fatalf("failed to scan git folders: %v", err)
}
if len(got) != len(tt.Want) {
t.Fatalf("expected %d git folders, got %d", len(tt.Want), len(got))
}
for i := range got {
if !slices.Contains(tt.Want, got[i]) {
t.Fatalf("expected %q to be in %q", got[i], tt.Want)
}
}
})
}
}