-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
70 lines (66 loc) · 1.41 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
package main
import (
"errors"
"testing"
)
func TestGetIssueID(t *testing.T) {
tests := []struct {
Name string
Given string
Expect string
Err error
}{
{
Name: "Happy Path",
Given: "https://user-testing.atlassian.net/browse/TOOL-936",
Expect: "TOOL-936",
Err: nil,
},
}
for _, tc := range tests {
t.Run(tc.Name, func(t *testing.T) {
result, err := getIssueID(tc.Given)
if !errors.Is(err, tc.Err) {
t.Fatalf("expected error to be %v, got: %v", tc.Err, err)
}
if result != tc.Expect {
t.Fatalf("expected result to be %v, got: %v", tc.Expect, result)
}
})
}
}
func TestCreateBranchName(t *testing.T) {
tests := []struct {
Name string
ID string
Summary string
Expect string
}{
{
Name: "Happy Path",
ID: "TOOL-936",
Summary: "abc def",
Expect: "TOOL-936--abc-def",
},
{
Name: "Leading spaces",
ID: "TOOL-936",
Summary: " Refactor specs for non ut marketing",
Expect: "TOOL-936--refactor-specs-for-non-ut-marketing",
},
{
Name: "Trailing spaces",
ID: "TOOL-936",
Summary: "Refactor specs for non ut marketing ",
Expect: "TOOL-936--refactor-specs-for-non-ut-marketing",
},
}
for _, tc := range tests {
t.Run(tc.Name, func(t *testing.T) {
name := createBranchName(tc.ID, tc.Summary)
if name != tc.Expect {
t.Fatalf("expected %v, got %v", tc.Expect, name)
}
})
}
}