-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
92 lines (78 loc) · 1.77 KB
/
main_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
85
86
87
88
89
90
91
92
package main
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestNewStore(t *testing.T) {
}
func TestValidPath(t *testing.T) {
type Case struct {
ID int
Path string
Valid bool
}
cases := []Case{
{1, "", false},
{2, ".", true},
{3, "..", true},
{4, "/", true},
{5, "/tmp", true},
{6, "./main_test.go", false},
}
for _, c := range cases {
res, err := validPath(c.Path)
if c.Valid {
t.Logf("case %d result is %s", c.ID, res)
}
if (err == nil) != c.Valid {
t.Errorf("case %d got %t should be %t", c.ID, (err == nil), c.Valid)
}
}
}
func TestValidFileTypes(t *testing.T) {
type Case struct {
ID int
List string
Res []string
Valid bool
}
cases := []Case{
{1, "", []string{}, false},
{2, "go", []string{"go"}, true},
{3, "go rb", []string{"go", "rb"}, true},
{4, "Go Rb", []string{"go", "rb"}, true},
{5, "Go Rb", []string{"go", "rb"}, true},
{6, "Go Rb Css html", []string{"go", "rb", "css", "html"}, false},
{7, "Go Rb Css html", []string{"css", "go", "html", "rb"}, true},
{8, "Go - .", []string{"-", ".", "go"}, true},
}
for _, c := range cases {
res, err := validFileTypes(c.List)
if c.Valid {
t.Logf("case %d result is %v", c.ID, res)
}
if (err != nil) && c.Valid {
t.Errorf("case %d got %t should be %t", c.ID, (err == nil), c.Valid)
}
if c.Valid && !cmp.Equal(res, c.Res) {
t.Errorf("case %d diffs: \n%s", c.ID, cmp.Diff(res, c.Res))
}
}
}
func TestValidScript(t *testing.T) {
type Case struct {
ID int
Script string
Valid bool
}
cases := []Case{
{1, "", false},
{2, "go version", true},
}
for _, c := range cases {
_, err := validScript(c.Script)
if (err == nil) != c.Valid {
t.Errorf("case %d got %t should be %t", c.ID, (err == nil), c.Valid)
}
}
}