Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit c1ce518

Browse files
authored
Merge pull request #2066 from alexandear/chore/t-fatal
chore: replace log.Fatal with t.Fatal in tests
2 parents e884d22 + 378abcc commit c1ce518

13 files changed

+131
-134
lines changed

.golangci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ linters-settings:
1919
locale: US
2020
ignore-words:
2121
- noteable
22+
revive:
23+
enable-all-rules: false
24+
rules:
25+
- name: deep-exit
2226

2327
linters:
2428
enable:
@@ -34,6 +38,7 @@ linters:
3438
- misspell
3539
- nakedret
3640
- nolintlint
41+
- revive
3742
- staticcheck
3843
- typecheck
3944
- unconvert

environments_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package gitlab
1919
import (
2020
"encoding/json"
2121
"fmt"
22-
"log"
2322
"net/http"
2423
"reflect"
2524
"testing"
@@ -67,7 +66,7 @@ func TestListEnvironments(t *testing.T) {
6766

6867
envs, _, err := client.Environments.ListEnvironments(1, &ListEnvironmentsOptions{Name: Ptr("review/fix-foo"), ListOptions: ListOptions{Page: 1, PerPage: 10}})
6968
if err != nil {
70-
log.Fatal(err)
69+
t.Fatal(err)
7170
}
7271

7372
createdAtWant, _ := time.Parse(timeLayout, "2013-10-02T10:12:29Z")
@@ -218,7 +217,7 @@ func TestCreateEnvironment(t *testing.T) {
218217
FluxResourcePath: Ptr("HelmRelease/flux-system"),
219218
})
220219
if err != nil {
221-
log.Fatal(err)
220+
t.Fatal(err)
222221
}
223222

224223
createdAtWant, _ := time.Parse(timeLayout, "2013-10-02T10:12:29Z")
@@ -294,7 +293,7 @@ func TestEditEnvironment(t *testing.T) {
294293
FluxResourcePath: Ptr("HelmRelease/flux-system"),
295294
})
296295
if err != nil {
297-
log.Fatal(err)
296+
t.Fatal(err)
298297
}
299298

300299
createdAtWant, _ := time.Parse(timeLayout, "2013-10-02T10:12:29Z")
@@ -336,7 +335,7 @@ func TestDeleteEnvironment(t *testing.T) {
336335
})
337336
_, err := client.Environments.DeleteEnvironment(1, 1)
338337
if err != nil {
339-
log.Fatal(err)
338+
t.Fatal(err)
340339
}
341340
}
342341

@@ -357,7 +356,7 @@ func TestStopEnvironment(t *testing.T) {
357356
})
358357
_, _, err := client.Environments.StopEnvironment(1, 1, &StopEnvironmentOptions{})
359358
if err != nil {
360-
log.Fatal(err)
359+
t.Fatal(err)
361360
}
362361
}
363362

epics_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package gitlab
1818

1919
import (
2020
"fmt"
21-
"log"
2221
"net/http"
2322
"reflect"
2423
"testing"
@@ -34,7 +33,7 @@ func TestGetEpic(t *testing.T) {
3433

3534
epic, _, err := client.Epics.GetEpic("7", 8)
3635
if err != nil {
37-
log.Fatal(err)
36+
t.Fatal(err)
3837
}
3938

4039
want := &Epic{
@@ -58,7 +57,7 @@ func TestDeleteEpic(t *testing.T) {
5857

5958
_, err := client.Epics.DeleteEpic("7", 8)
6059
if err != nil {
61-
log.Fatal(err)
60+
t.Fatal(err)
6261
}
6362
}
6463

@@ -78,7 +77,7 @@ func TestListGroupEpics(t *testing.T) {
7877

7978
epics, _, err := client.Epics.ListGroupEpics("7", listGroupEpics)
8079
if err != nil {
81-
log.Fatal(err)
80+
t.Fatal(err)
8281
}
8382

8483
want := []*Epic{{
@@ -108,7 +107,7 @@ func TestCreateEpic(t *testing.T) {
108107

109108
epic, _, err := client.Epics.CreateEpic("7", createEpicOptions)
110109
if err != nil {
111-
log.Fatal(err)
110+
t.Fatal(err)
112111
}
113112

114113
want := &Epic{
@@ -138,7 +137,7 @@ func TestUpdateEpic(t *testing.T) {
138137

139138
epic, _, err := client.Epics.UpdateEpic("7", 8, updateEpicOptions)
140139
if err != nil {
141-
log.Fatal(err)
140+
t.Fatal(err)
142141
}
143142

144143
want := &Epic{

event_parsing_systemhook_test.go

+24-24
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func TestParseSystemhookPush(t *testing.T) {
26-
payload := loadFixture("testdata/systemhooks/push.json")
26+
payload := loadFixture(t, "testdata/systemhooks/push.json")
2727

2828
parsedEvent, err := ParseSystemhook(payload)
2929
if err != nil {
@@ -38,7 +38,7 @@ func TestParseSystemhookPush(t *testing.T) {
3838
}
3939

4040
func TestParseSystemhookTagPush(t *testing.T) {
41-
payload := loadFixture("testdata/systemhooks/tag_push.json")
41+
payload := loadFixture(t, "testdata/systemhooks/tag_push.json")
4242

4343
parsedEvent, err := ParseSystemhook(payload)
4444
if err != nil {
@@ -53,7 +53,7 @@ func TestParseSystemhookTagPush(t *testing.T) {
5353
}
5454

5555
func TestParseSystemhookMergeRequest(t *testing.T) {
56-
payload := loadFixture("testdata/systemhooks/merge_request.json")
56+
payload := loadFixture(t, "testdata/systemhooks/merge_request.json")
5757

5858
parsedEvent, err := ParseSystemhook(payload)
5959
if err != nil {
@@ -68,7 +68,7 @@ func TestParseSystemhookMergeRequest(t *testing.T) {
6868
}
6969

7070
func TestParseSystemhookRepositoryUpdate(t *testing.T) {
71-
payload := loadFixture("testdata/systemhooks/repository_update.json")
71+
payload := loadFixture(t, "testdata/systemhooks/repository_update.json")
7272

7373
parsedEvent, err := ParseSystemhook(payload)
7474
if err != nil {
@@ -87,11 +87,11 @@ func TestParseSystemhookProject(t *testing.T) {
8787
event string
8888
payload []byte
8989
}{
90-
{"project_create", loadFixture("testdata/systemhooks/project_create.json")},
91-
{"project_update", loadFixture("testdata/systemhooks/project_update.json")},
92-
{"project_destroy", loadFixture("testdata/systemhooks/project_destroy.json")},
93-
{"project_transfer", loadFixture("testdata/systemhooks/project_transfer.json")},
94-
{"project_rename", loadFixture("testdata/systemhooks/project_rename.json")},
90+
{"project_create", loadFixture(t, "testdata/systemhooks/project_create.json")},
91+
{"project_update", loadFixture(t, "testdata/systemhooks/project_update.json")},
92+
{"project_destroy", loadFixture(t, "testdata/systemhooks/project_destroy.json")},
93+
{"project_transfer", loadFixture(t, "testdata/systemhooks/project_transfer.json")},
94+
{"project_rename", loadFixture(t, "testdata/systemhooks/project_rename.json")},
9595
}
9696
for _, tc := range tests {
9797
t.Run(tc.event, func(t *testing.T) {
@@ -113,9 +113,9 @@ func TestParseSystemhookGroup(t *testing.T) {
113113
event string
114114
payload []byte
115115
}{
116-
{"group_create", loadFixture("testdata/systemhooks/group_create.json")},
117-
{"group_destroy", loadFixture("testdata/systemhooks/group_destroy.json")},
118-
{"group_rename", loadFixture("testdata/systemhooks/group_rename.json")},
116+
{"group_create", loadFixture(t, "testdata/systemhooks/group_create.json")},
117+
{"group_destroy", loadFixture(t, "testdata/systemhooks/group_destroy.json")},
118+
{"group_rename", loadFixture(t, "testdata/systemhooks/group_rename.json")},
119119
}
120120
for _, tc := range tests {
121121
t.Run(tc.event, func(t *testing.T) {
@@ -137,10 +137,10 @@ func TestParseSystemhookUser(t *testing.T) {
137137
event string
138138
payload []byte
139139
}{
140-
{"user_create", loadFixture("testdata/systemhooks/user_create.json")},
141-
{"user_destroy", loadFixture("testdata/systemhooks/user_destroy.json")},
142-
{"user_rename", loadFixture("testdata/systemhooks/user_rename.json")},
143-
{"user_failed_login", loadFixture("testdata/systemhooks/user_failed_login.json")},
140+
{"user_create", loadFixture(t, "testdata/systemhooks/user_create.json")},
141+
{"user_destroy", loadFixture(t, "testdata/systemhooks/user_destroy.json")},
142+
{"user_rename", loadFixture(t, "testdata/systemhooks/user_rename.json")},
143+
{"user_failed_login", loadFixture(t, "testdata/systemhooks/user_failed_login.json")},
144144
}
145145
for _, tc := range tests {
146146
t.Run(tc.event, func(t *testing.T) {
@@ -162,9 +162,9 @@ func TestParseSystemhookUserGroup(t *testing.T) {
162162
event string
163163
payload []byte
164164
}{
165-
{"user_add_to_group", loadFixture("testdata/systemhooks/user_add_to_group.json")},
166-
{"user_remove_from_group", loadFixture("testdata/systemhooks/user_remove_from_group.json")},
167-
{"user_update_for_group", loadFixture("testdata/systemhooks/user_update_for_group.json")},
165+
{"user_add_to_group", loadFixture(t, "testdata/systemhooks/user_add_to_group.json")},
166+
{"user_remove_from_group", loadFixture(t, "testdata/systemhooks/user_remove_from_group.json")},
167+
{"user_update_for_group", loadFixture(t, "testdata/systemhooks/user_update_for_group.json")},
168168
}
169169
for _, tc := range tests {
170170
t.Run(tc.event, func(t *testing.T) {
@@ -186,9 +186,9 @@ func TestParseSystemhookUserTeam(t *testing.T) {
186186
event string
187187
payload []byte
188188
}{
189-
{"user_add_to_team", loadFixture("testdata/systemhooks/user_add_to_team.json")},
190-
{"user_remove_from_team", loadFixture("testdata/systemhooks/user_remove_from_team.json")},
191-
{"user_update_for_team", loadFixture("testdata/systemhooks/user_update_for_team.json")},
189+
{"user_add_to_team", loadFixture(t, "testdata/systemhooks/user_add_to_team.json")},
190+
{"user_remove_from_team", loadFixture(t, "testdata/systemhooks/user_remove_from_team.json")},
191+
{"user_update_for_team", loadFixture(t, "testdata/systemhooks/user_update_for_team.json")},
192192
}
193193
for _, tc := range tests {
194194
t.Run(tc.event, func(t *testing.T) {
@@ -206,11 +206,11 @@ func TestParseSystemhookUserTeam(t *testing.T) {
206206
}
207207

208208
func TestParseHookSystemHook(t *testing.T) {
209-
parsedEvent1, err := ParseHook("System Hook", loadFixture("testdata/systemhooks/merge_request.json"))
209+
parsedEvent1, err := ParseHook("System Hook", loadFixture(t, "testdata/systemhooks/merge_request.json"))
210210
if err != nil {
211211
t.Errorf("Error parsing build hook: %s", err)
212212
}
213-
parsedEvent2, err := ParseSystemhook(loadFixture("testdata/systemhooks/merge_request.json"))
213+
parsedEvent2, err := ParseSystemhook(loadFixture(t, "testdata/systemhooks/merge_request.json"))
214214
if err != nil {
215215
t.Errorf("Error parsing build hook: %s", err)
216216
}

0 commit comments

Comments
 (0)