-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
95 lines (87 loc) · 1.79 KB
/
utils_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
package main
import (
"testing"
"github.com/iver-wharf/wharf-api/v5/pkg/model/database"
"github.com/stretchr/testify/assert"
)
func TestFindDefaultGroupSuccess(t *testing.T) {
var (
main = database.Branch{Name: "main", Default: true}
b1 = database.Branch{Name: "b1"}
b2 = database.Branch{Name: "b2"}
b3 = database.Branch{Name: "b3"}
b4 = database.Branch{Name: "b4"}
)
tests := []struct {
name string
branches []database.Branch
}{
{
name: "at the beginning",
branches: []database.Branch{main, b1, b2, b3, b4},
},
{
name: "in the middle",
branches: []database.Branch{b1, b2, main, b3, b4},
},
{
name: "at the end",
branches: []database.Branch{b1, b2, b3, b4, main},
},
{
name: "multiple",
branches: []database.Branch{b1, main, main, b4, main},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, ok := findDefaultBranch(tt.branches)
assert.True(t, ok)
assert.Equal(t, main, got)
})
}
}
func TestFindDefaultGroupFail(t *testing.T) {
branches := []database.Branch{
{Name: "b1"},
{Name: "b2"},
{Name: "b3"},
{Name: "b4"},
}
_, ok := findDefaultBranch(branches)
assert.False(t, ok)
}
func TestNewLikeContainsValue(t *testing.T) {
testCases := []struct {
name string
input string
want string
}{
{
name: "empty string",
input: "",
want: "%",
},
{
name: "special chars",
input: "foo%bar?moo_doo",
want: `%foo\%bar\?moo\_doo%`,
},
{
name: "escape",
input: `foo\\bar`,
want: `%foo\\\\bar%`,
},
{
name: "escaped special char",
input: `foo\%bar`,
want: `%foo\\\%bar%`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := newLikeContainsValue(tc.input)
assert.Equal(t, tc.want, got)
})
}
}