forked from k1LoW/runn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_test.go
84 lines (79 loc) · 2.01 KB
/
path_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package runn
import (
"os"
"testing"
)
func TestFetchPaths(t *testing.T) {
tests := []struct {
pathp string
want int
wantErr bool
}{
{"testdata/book/book.yml", 1, false},
{"testdata/book/notexist.yml", 0, true},
{"testdata/book/runn_*", 4, false},
{"testdata/book/book.yml:testdata/book/http.yml", 2, false},
{"testdata/book/book.yml:testdata/book/runn_*.yml", 5, false},
{"testdata/book/book.yml:testdata/book/book.yml", 1, false},
{"testdata/book/runn_0_success.yml:testdata/book/runn_*.yml", 4, false},
{"github://k1LoW/runn/testdata/book/book.yml", 1, false},
{"github://k1LoW/runn/testdata/book/runn_*", 4, false},
{"https://raw.githubusercontent.com/k1LoW/runn/main/testdata/book/book.yml", 1, false},
}
if os.Getenv("CI") == "" {
// GITHUB_TOKEN for GitHub Actions does not have permission to access Gist
tests = append(tests, []struct {
pathp string
want int
wantErr bool
}{
// Single file
{"gist://b908ae0721300ca45f4e8b81b6be246d", 1, false},
{"gist://b908ae0721300ca45f4e8b81b6be246d/book.yml", 1, false},
// Multiple files
{"gist://def6fa739fba3fcf211b018f41630adc", 0, true},
{"gist://def6fa739fba3fcf211b018f41630adc/book.yml", 1, false},
}...)
}
t.Cleanup(func() {
if err := RemoveCacheDir(); err != nil {
t.Fatal(err)
}
})
for _, tt := range tests {
t.Run(tt.pathp, func(t *testing.T) {
paths, err := fetchPaths(tt.pathp)
if err != nil {
if !tt.wantErr {
t.Errorf("got %v", err)
}
return
}
if tt.wantErr {
t.Errorf("want err")
}
got := len(paths)
if got != tt.want {
t.Errorf("got %v\nwant %v", got, tt.want)
}
})
}
}
func TestShortenPath(t *testing.T) {
tests := []struct {
in string
want string
}{
{"path/to/book.yml", "p/t/book.yml"},
{"book.yml", "book.yml"},
{"/path/to/book.yml", "/p/t/book.yml"},
}
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
got := ShortenPath(tt.in)
if got != tt.want {
t.Errorf("got %v\nwant %v", got, tt.want)
}
})
}
}