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

Commit

Permalink
Merge pull request #2066 from alexandear/chore/t-fatal
Browse files Browse the repository at this point in the history
chore: replace log.Fatal with t.Fatal in tests
  • Loading branch information
RicePatrick authored Nov 25, 2024
2 parents e884d22 + 378abcc commit c1ce518
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 134 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ linters-settings:
locale: US
ignore-words:
- noteable
revive:
enable-all-rules: false
rules:
- name: deep-exit

linters:
enable:
Expand All @@ -34,6 +38,7 @@ linters:
- misspell
- nakedret
- nolintlint
- revive
- staticcheck
- typecheck
- unconvert
Expand Down
11 changes: 5 additions & 6 deletions environments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package gitlab
import (
"encoding/json"
"fmt"
"log"
"net/http"
"reflect"
"testing"
Expand Down Expand Up @@ -67,7 +66,7 @@ func TestListEnvironments(t *testing.T) {

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

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

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

createdAtWant, _ := time.Parse(timeLayout, "2013-10-02T10:12:29Z")
Expand Down Expand Up @@ -336,7 +335,7 @@ func TestDeleteEnvironment(t *testing.T) {
})
_, err := client.Environments.DeleteEnvironment(1, 1)
if err != nil {
log.Fatal(err)
t.Fatal(err)
}
}

Expand All @@ -357,7 +356,7 @@ func TestStopEnvironment(t *testing.T) {
})
_, _, err := client.Environments.StopEnvironment(1, 1, &StopEnvironmentOptions{})
if err != nil {
log.Fatal(err)
t.Fatal(err)
}
}

Expand Down
11 changes: 5 additions & 6 deletions epics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package gitlab

import (
"fmt"
"log"
"net/http"
"reflect"
"testing"
Expand All @@ -34,7 +33,7 @@ func TestGetEpic(t *testing.T) {

epic, _, err := client.Epics.GetEpic("7", 8)
if err != nil {
log.Fatal(err)
t.Fatal(err)
}

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

_, err := client.Epics.DeleteEpic("7", 8)
if err != nil {
log.Fatal(err)
t.Fatal(err)
}
}

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

epics, _, err := client.Epics.ListGroupEpics("7", listGroupEpics)
if err != nil {
log.Fatal(err)
t.Fatal(err)
}

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

epic, _, err := client.Epics.CreateEpic("7", createEpicOptions)
if err != nil {
log.Fatal(err)
t.Fatal(err)
}

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

epic, _, err := client.Epics.UpdateEpic("7", 8, updateEpicOptions)
if err != nil {
log.Fatal(err)
t.Fatal(err)
}

want := &Epic{
Expand Down
48 changes: 24 additions & 24 deletions event_parsing_systemhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

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

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

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

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

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

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

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

parsedEvent, err := ParseSystemhook(payload)
if err != nil {
Expand All @@ -87,11 +87,11 @@ func TestParseSystemhookProject(t *testing.T) {
event string
payload []byte
}{
{"project_create", loadFixture("testdata/systemhooks/project_create.json")},
{"project_update", loadFixture("testdata/systemhooks/project_update.json")},
{"project_destroy", loadFixture("testdata/systemhooks/project_destroy.json")},
{"project_transfer", loadFixture("testdata/systemhooks/project_transfer.json")},
{"project_rename", loadFixture("testdata/systemhooks/project_rename.json")},
{"project_create", loadFixture(t, "testdata/systemhooks/project_create.json")},
{"project_update", loadFixture(t, "testdata/systemhooks/project_update.json")},
{"project_destroy", loadFixture(t, "testdata/systemhooks/project_destroy.json")},
{"project_transfer", loadFixture(t, "testdata/systemhooks/project_transfer.json")},
{"project_rename", loadFixture(t, "testdata/systemhooks/project_rename.json")},
}
for _, tc := range tests {
t.Run(tc.event, func(t *testing.T) {
Expand All @@ -113,9 +113,9 @@ func TestParseSystemhookGroup(t *testing.T) {
event string
payload []byte
}{
{"group_create", loadFixture("testdata/systemhooks/group_create.json")},
{"group_destroy", loadFixture("testdata/systemhooks/group_destroy.json")},
{"group_rename", loadFixture("testdata/systemhooks/group_rename.json")},
{"group_create", loadFixture(t, "testdata/systemhooks/group_create.json")},
{"group_destroy", loadFixture(t, "testdata/systemhooks/group_destroy.json")},
{"group_rename", loadFixture(t, "testdata/systemhooks/group_rename.json")},
}
for _, tc := range tests {
t.Run(tc.event, func(t *testing.T) {
Expand All @@ -137,10 +137,10 @@ func TestParseSystemhookUser(t *testing.T) {
event string
payload []byte
}{
{"user_create", loadFixture("testdata/systemhooks/user_create.json")},
{"user_destroy", loadFixture("testdata/systemhooks/user_destroy.json")},
{"user_rename", loadFixture("testdata/systemhooks/user_rename.json")},
{"user_failed_login", loadFixture("testdata/systemhooks/user_failed_login.json")},
{"user_create", loadFixture(t, "testdata/systemhooks/user_create.json")},
{"user_destroy", loadFixture(t, "testdata/systemhooks/user_destroy.json")},
{"user_rename", loadFixture(t, "testdata/systemhooks/user_rename.json")},
{"user_failed_login", loadFixture(t, "testdata/systemhooks/user_failed_login.json")},
}
for _, tc := range tests {
t.Run(tc.event, func(t *testing.T) {
Expand All @@ -162,9 +162,9 @@ func TestParseSystemhookUserGroup(t *testing.T) {
event string
payload []byte
}{
{"user_add_to_group", loadFixture("testdata/systemhooks/user_add_to_group.json")},
{"user_remove_from_group", loadFixture("testdata/systemhooks/user_remove_from_group.json")},
{"user_update_for_group", loadFixture("testdata/systemhooks/user_update_for_group.json")},
{"user_add_to_group", loadFixture(t, "testdata/systemhooks/user_add_to_group.json")},
{"user_remove_from_group", loadFixture(t, "testdata/systemhooks/user_remove_from_group.json")},
{"user_update_for_group", loadFixture(t, "testdata/systemhooks/user_update_for_group.json")},
}
for _, tc := range tests {
t.Run(tc.event, func(t *testing.T) {
Expand All @@ -186,9 +186,9 @@ func TestParseSystemhookUserTeam(t *testing.T) {
event string
payload []byte
}{
{"user_add_to_team", loadFixture("testdata/systemhooks/user_add_to_team.json")},
{"user_remove_from_team", loadFixture("testdata/systemhooks/user_remove_from_team.json")},
{"user_update_for_team", loadFixture("testdata/systemhooks/user_update_for_team.json")},
{"user_add_to_team", loadFixture(t, "testdata/systemhooks/user_add_to_team.json")},
{"user_remove_from_team", loadFixture(t, "testdata/systemhooks/user_remove_from_team.json")},
{"user_update_for_team", loadFixture(t, "testdata/systemhooks/user_update_for_team.json")},
}
for _, tc := range tests {
t.Run(tc.event, func(t *testing.T) {
Expand All @@ -206,11 +206,11 @@ func TestParseSystemhookUserTeam(t *testing.T) {
}

func TestParseHookSystemHook(t *testing.T) {
parsedEvent1, err := ParseHook("System Hook", loadFixture("testdata/systemhooks/merge_request.json"))
parsedEvent1, err := ParseHook("System Hook", loadFixture(t, "testdata/systemhooks/merge_request.json"))
if err != nil {
t.Errorf("Error parsing build hook: %s", err)
}
parsedEvent2, err := ParseSystemhook(loadFixture("testdata/systemhooks/merge_request.json"))
parsedEvent2, err := ParseSystemhook(loadFixture(t, "testdata/systemhooks/merge_request.json"))
if err != nil {
t.Errorf("Error parsing build hook: %s", err)
}
Expand Down
Loading

0 comments on commit c1ce518

Please sign in to comment.