forked from treeverse/lakeFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_test.go
107 lines (103 loc) · 2.46 KB
/
validate_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package catalog
import (
"testing"
)
func TestValidate(t *testing.T) {
type args struct {
validators ValidateFields
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: false,
},
{
name: "all pass",
args: args{
validators: ValidateFields{
{Name: "v1", IsValid: func() bool { return true }},
{Name: "v2", IsValid: func() bool { return true }},
{Name: "v3", IsValid: func() bool { return true }},
},
},
wantErr: false,
},
{
name: "all fail",
args: args{
validators: ValidateFields{
{Name: "v1", IsValid: func() bool { return false }},
{Name: "v2", IsValid: func() bool { return false }},
{Name: "v3", IsValid: func() bool { return false }},
},
},
wantErr: true,
},
{
name: "one of each",
args: args{
validators: ValidateFields{
{Name: "v1", IsValid: func() bool { return true }},
{Name: "v2", IsValid: func() bool { return false }},
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := Validate(tt.args.validators); (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestIsValidBranchName(t *testing.T) {
tests := []struct {
name string
input string
want bool
}{
{name: "simple", input: "branch", want: true},
{name: "empty", input: "", want: false},
{name: "short", input: "a", want: true},
{name: "space", input: "got space", want: false},
{name: "special", input: "/branch", want: false},
{name: "dash", input: "a-branch", want: true},
{name: "leading-dash", input: "-branch", want: false},
{name: "underscores", input: "__", want: true},
{name: "backslash", input: "a\\branch", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := IsValidBranchName(tt.input)
if got != tt.want {
t.Errorf("IsValidBranchName() got = %t, want %t", got, tt.want)
}
})
}
}
func TestIsNonEmptyString(t *testing.T) {
tests := []struct {
name string
input string
want bool
}{
{name: "simple", input: "data", want: true},
{name: "empty", input: "", want: false},
{name: "space", input: "s p a c e", want: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := IsNonEmptyString(tt.input)
if got != tt.want {
t.Errorf("IsNonEmptyString() got = %t, want %t", got, tt.want)
}
})
}
}