This repository has been archived by the owner on Apr 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjira_test.go
120 lines (109 loc) · 3.02 KB
/
jira_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
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"os"
"reflect"
"testing"
)
func TestFindJiraIssueKey(t *testing.T) {
type test struct {
input string
want []string
}
tests := []test{
{input: "12345", want: nil},
{input: "abc JI-1234", want: nil},
{input: "JI-1234", want: []string{"JI-1234"}},
{input: "JI-1234 abc", want: []string{"JI-1234"}},
{input: "JI-1234 abc\nnnn JI-5678 xyz\n", want: []string{"JI-1234"}},
{input: "JI-1234 abc\nJI-5678 xyz\n", want: []string{"JI-1234", "JI-5678"}},
{input: "JI-1234 abc\nJI-5678 xyz\nIN-0001", want: []string{"JI-1234", "JI-5678", "IN-0001"}},
}
for _, tc := range tests {
got := findJiraIssueKeys(tc.input)
if !reflect.DeepEqual(tc.want, got) {
t.Fatalf("expected: %v, got: %v", tc.want, got)
}
}
}
func TestShouldReturnErrorIfInvalidJiraJsonPassedIn(t *testing.T) {
invalidJSON := []byte(`abc123`)
_, err := parseJiraIssue(invalidJSON)
if !ErrorContains(err, "cannot create object - invalid json") {
t.Errorf("unexpected error message: %v", err)
}
}
func TestShouldGetJiraIssueFromValidJson(t *testing.T) {
filename := "./sample-data/jira-issue-sample.json"
validJSON, err := os.ReadFile(filename)
if err != nil {
t.Errorf("could not read file: %s", err)
}
_, err = parseJiraIssue(validJSON)
if err != nil {
t.Errorf("unexpected error from ParseJiraIssue: %v", err)
}
}
func TestFindHeader(t *testing.T) {
type test struct {
input string
want string
}
tests := []test{
{input: "", want: ""},
{input: "My release notes", want: ""},
{input: "not a heading", want: ""},
{input: "h1. Blah", want: "Blah"},
{input: "h2. Improvements", want: "Improvements"},
{input: "h3. Test Heading", want: "Test Heading"},
{input: "h4. Breaking Changes", want: "Breaking Changes"},
}
for _, tc := range tests {
got := findHeader(tc.input)
if !reflect.DeepEqual(tc.want, got) {
t.Fatalf("expected: %v, got: %v", tc.want, got)
}
}
}
func TestExtractHeadings(t *testing.T) {
type test struct {
input string
want []Group
}
tests := []test{
{input: "", want: []Group{}},
{input: "My release notes", want: []Group{
{
Name: "Changes",
BulletPoints: []string{"My release notes"},
},
}},
{input: "h1. Breaking Changes\nMy release notes", want: []Group{
{
Name: "Breaking Changes",
BulletPoints: []string{"My release notes"},
},
}},
{input: "h2. Nested List\n* Item 1\n** Nested item 1\n** Nested item 2", want: []Group{
{
Name: "Nested List",
BulletPoints: []string{"* Item 1", "** Nested item 1", "** Nested item 2"},
},
}},
{input: "h3. Significant Changes\n* Point 1\n* Point 2\n\nh3. Breaking Changes\nMy release notes", want: []Group{
{
Name: "Significant Changes",
BulletPoints: []string{"* Point 1", "* Point 2"},
},
{
Name: "Breaking Changes",
BulletPoints: []string{"My release notes"},
},
}},
}
for _, tc := range tests {
got := extractGroups(tc.input)
if !reflect.DeepEqual(tc.want, got) {
t.Fatalf("expected: %v, got: %v", tc.want, got)
}
}
}