-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
172 lines (158 loc) · 6.69 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package main
import (
"bytes"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGet(t *testing.T) {
intendedResponse := "# Changes from release 2022/06 to 2022/07\n2. Bug - Corrected Alderney (EGJA) runway coords - thanks to @sdkjsdklfj (John Doe)\n3. AIRAC (2207) - Updated Cranfield (EGTC) SMR - thanks to @sdfsdf (Doe John)\nfakeline"
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, intendedResponse)
}))
defer server.Close()
actualbytes := GetWebChangelog(server.URL)
assert.Equal(t, []byte(intendedResponse), actualbytes)
}
func TestGetWillFail(t *testing.T) {
assert.Panics(t, func() { GetWebChangelog("") })
}
func TestGenerateChangelog(t *testing.T) {
file := "# Changes from release 2022/06 to 2022/07\n2. Bug - Corrected Alderney (EGJA) runway coords - thanks to @sdkjsdklfj (John Doe)\n3. AIRAC (2207) - Updated Cranfield (EGTC) SMR - thanks to @sdfsdf (Doe John)\nfakeline"
actualChangelog, _ := GenerateChangelog([]byte(file))
intendedChangelog := Changelog{
Changes: []string{"Bug - Corrected Alderney (EGJA) runway coords - thanks to @sdkjsdklfj (John Doe)", "AIRAC (2207) - Updated Cranfield (EGTC) SMR - thanks to @sdfsdf (Doe John)"},
AIRACList: []string{"AIRAC (2207) - Updated Cranfield (EGTC) SMR"},
AIRACMap: map[string][]string{
"2207": {"Updated Cranfield (EGTC) SMR"},
},
AIRACs: []int{2207},
Contributors: []string{"John Doe", "Doe John"},
OtherMap: map[string][]string{"Bug": {"Corrected Alderney (EGJA) runway coords"}},
Other: []string{"Bug - Corrected Alderney (EGJA) runway coords"},
}
assert.Equal(t, intendedChangelog, actualChangelog)
}
func TestGetChanges(t *testing.T) {
fakefile := "# Changes from release 2022/06 to 2022/07\n2. Bug - Corrected Alderney (EGJA) runway coords - thanks to @sdkjsdklfj (John Doe)\n3. AIRAC (2207) - Updated Cranfield (EGTC) SMR - thanks to @sdfsdf (Doe John)\nfakeline\n" +
"# Changes from 2022/05 to 2022/06\n1. AIRAC (2202) - This shouldn't be included - thanks to @sdsdkjf (Tom)\n"
changes := GetChanges([]byte(fakefile))
intendedChanges := []string{
"Bug - Corrected Alderney (EGJA) runway coords - thanks to @sdkjsdklfj (John Doe)",
"AIRAC (2207) - Updated Cranfield (EGTC) SMR - thanks to @sdfsdf (Doe John)",
}
assert.ElementsMatch(t, intendedChanges, changes)
}
func TestChangesSorter(t *testing.T) {
testChangelog := Changelog{}
changes := []string{
"Bug - Corrected Alderney (EGJA) runway coords - thanks to @sdkjsdklfj (John Doe)",
"AIRAC (2207) - Updated Cranfield (EGTC) SMR - thanks to @sdfsdf (Doe John)",
"AIRAC (2207) - Updated Inverness (EGPE) RWYs 05/23 and 11/29 coords - this was very silly - thanks to @sdfsdf (Smith)",
"Enhancement - Added missing heli points and holds to Gloucestershire (EGBJ) SMR",
}
testChangelog = Changelog{
Changes: changes,
}
airacList, otherList := testChangelog.ChangesSorter()
intendedAiracList := []string{
"AIRAC (2207) - Updated Cranfield (EGTC) SMR",
"AIRAC (2207) - Updated Inverness (EGPE) RWYs 05/23 and 11/29 coords - this was very silly",
}
intendedOtherList := []string{
"Bug - Corrected Alderney (EGJA) runway coords",
"Enhancement - Added missing heli points and holds to Gloucestershire (EGBJ) SMR",
}
assert.ElementsMatch(t, intendedAiracList, airacList)
assert.ElementsMatch(t, intendedOtherList, otherList)
}
func TestAiracMapGen(t *testing.T) {
testChangelog := Changelog{}
airacChanges := []string{
"AIRAC (2207) - Updated Cranfield (EGTC) SMR",
"AIRAC (2206) - Updated Inverness (EGPE) RWYs 05/23 and 11/29 coords - this was very silly",
"AIRAC (2205)",
}
testChangelog = Changelog{
AIRACList: airacChanges,
}
airacMap, airacs, _ := testChangelog.AIRACMapGen()
intendedAiracMap := map[string][]string{
"2206": {"Updated Inverness (EGPE) RWYs 05/23 and 11/29 coords - this was very silly"},
"2207": {"Updated Cranfield (EGTC) SMR"},
}
intendedAiracs := []int{2207, 2206}
assert.Equal(t, intendedAiracMap, airacMap)
assert.Equal(t, intendedAiracs, airacs)
}
func TestContribGen(t *testing.T) {
testChangelog := Changelog{}
changes := []string{
"Bug - Corrected Alderney (EGJA) runway coords - thanks to @sdkjsdklfj (John Doe)",
"AIRAC (2207) - Updated Cranfield (EGTC) SMR - thanks to @sdfsdf (Doe John)",
"AIRAC (2207) - Updated Inverness (EGPE) RWYs 05/23 and 11/29 coords - this was very silly - thanks to @sdfsdf (Smith)",
"Enhancement - Added missing heli points and holds to Gloucestershire (EGBJ) SMR",
}
testChangelog = Changelog{
Changes: changes,
}
contribs := testChangelog.ContribGen()
intendedContribs := []string{
"Smith",
"John Doe",
"Doe John",
}
assert.ElementsMatch(t, intendedContribs, contribs)
}
func TestAIRACOutput(t *testing.T) {
c := Changelog{
AIRACs: []int{2207, 2206},
AIRACMap: map[string][]string{
"2207": {"Test 1", "Test 2"},
"2206": {"Test 3", "Test 4", "Test 5"},
},
}
buf := bytes.Buffer{}
OutputAIRAC(&buf, c)
expectedAIRACOutput := "--- AIRACs: ---\n2207:\nTest 1\nTest 2\n\n2206:\nTest 3\nTest 4\nTest 5\n"
assert.Equal(t, expectedAIRACOutput, buf.String())
}
func TestOutputOther(t *testing.T) {
c := Changelog{
OtherMap: map[string][]string{"Enhancement": {"Deleted Luton"}, "Bug": {"Removed all Gatwick (EGKK) SIDs"}},
}
buf := bytes.Buffer{}
OutputOther(&buf, c)
expectedOtherOutput := "--- Other: ---\nBug:\nRemoved all Gatwick (EGKK) SIDs\n\nEnhancement:\nDeleted Luton\n"
assert.Equal(t, expectedOtherOutput, buf.String())
}
func TestOutputContribs(t *testing.T) {
c := Changelog{
Contributors: []string{"John Doe", "Tim", "Sam Smith"},
}
buf := bytes.Buffer{}
OutputContribs(&buf, c)
expectedContribOutput := "--- Contributors: ---\nJohn Doe\nTim\nSam Smith\n"
assert.Equal(t, expectedContribOutput, buf.String())
}
func TestOutput(t *testing.T) {
c := Changelog{
Contributors: []string{"John Doe", "Tim", "Sam Smith"},
Other: []string{"Enhancement - Deleted Luton", "Bug - Removed all Gatwick (EGKK) SIDs"},
OtherMap: map[string][]string{"Enhancement": {"Deleted Luton"}, "Bug": {"Removed all Gatwick (EGKK) SIDs"}},
AIRACs: []int{2207, 2206},
AIRACMap: map[string][]string{
"2207": {"Test 1", "Test 2"},
"2206": {"Test 3", "Test 4", "Test 5"},
},
}
buf := bytes.Buffer{}
Output(&buf, c)
expectedAIRACOutput := "--- AIRACs: ---\n2207:\nTest 1\nTest 2\n\n2206:\nTest 3\nTest 4\nTest 5\n"
expectedOtherOutput := "--- Other: ---\nBug:\nRemoved all Gatwick (EGKK) SIDs\n\nEnhancement:\nDeleted Luton\n"
expectedContribOutput := "--- Contributors: ---\nJohn Doe\nTim\nSam Smith\n"
expectedOutput := expectedAIRACOutput + "\n" + expectedOtherOutput + "\n" + expectedContribOutput
assert.Equal(t, expectedOutput, buf.String())
}