-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
68 lines (59 loc) · 1.54 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
package main
import (
"testing"
)
func TestConfiguration(t *testing.T) {
t.Run("HasJira", func(t *testing.T) {
tests := []struct {
token string
user string
url string
valid bool
}{
{token: "", user: "", url: "", valid: false},
{token: "abc", user: "", url: "", valid: false},
{token: "", user: "abc", url: "", valid: false},
{token: "", user: "", url: "abc", valid: false},
{token: "abc", user: "anonymous", url: "atlassian", valid: true},
}
for _, test := range tests {
result := Config{
issuePattern: "",
jiraToken: test.token,
jiraUser: test.user,
jiraURL: test.url,
}
if result.HasJira() != test.valid {
t.Errorf("HashJira() wanted: %t, got: %t", test.valid, result.HasJira())
}
}
})
}
func TestBranch(t *testing.T) {
t.Run("DisplayName hides the refs/heads/ prefix", func(t *testing.T) {
branch := Branch{Name: "refs/heads/helpful-branch-name"}
want := "helpful-branch-name"
got := branch.DisplayName()
if got != want {
t.Errorf("Expected display name to be %s, but was %s", want, got)
}
})
}
func TestJiraTitleToBranchName(t *testing.T) {
tests := []struct {
title string
prefix string
delimiter string
want string
}{
{"Hello World", "P", "-", "P-hello-world"},
{"Extra Space", "P", "-", "P-extra-space"},
{"Hello world!", "P", "-", "P-hello-world"},
}
for _, test := range tests {
got := formatBranchName(test.title, test.prefix, test.delimiter)
if got != test.want {
t.Errorf("Wanted %s, got %s", test.want, got)
}
}
}