From 378abccaf8b4de3186d8f186fc92a6972b00c856 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Mon, 25 Nov 2024 14:18:00 +0200 Subject: [PATCH] chore: replace log.Fatal with t.Fatal --- .golangci.yml | 5 +++ environments_test.go | 11 +++--- epics_test.go | 11 +++--- event_parsing_systemhook_test.go | 48 +++++++++++++------------- event_parsing_webhook_test.go | 40 +++++++++++----------- event_webhook_types_test.go | 36 +++++++++---------- gitlab_test.go | 6 ++-- group_import_export_test.go | 7 ++-- group_labels_test.go | 15 ++++---- issues_statistics_test.go | 7 ++-- issues_test.go | 59 ++++++++++++++++---------------- labels_test.go | 15 ++++---- merge_requests_test.go | 5 ++- 13 files changed, 131 insertions(+), 134 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7c05feeef..70d7db87c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,6 +19,10 @@ linters-settings: locale: US ignore-words: - noteable + revive: + enable-all-rules: false + rules: + - name: deep-exit linters: enable: @@ -34,6 +38,7 @@ linters: - misspell - nakedret - nolintlint + - revive - staticcheck - typecheck - unconvert diff --git a/environments_test.go b/environments_test.go index a4b0ad6ed..1dd278b1e 100644 --- a/environments_test.go +++ b/environments_test.go @@ -19,7 +19,6 @@ package gitlab import ( "encoding/json" "fmt" - "log" "net/http" "reflect" "testing" @@ -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") @@ -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") @@ -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") @@ -336,7 +335,7 @@ func TestDeleteEnvironment(t *testing.T) { }) _, err := client.Environments.DeleteEnvironment(1, 1) if err != nil { - log.Fatal(err) + t.Fatal(err) } } @@ -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) } } diff --git a/epics_test.go b/epics_test.go index 06720af07..33126af8d 100644 --- a/epics_test.go +++ b/epics_test.go @@ -18,7 +18,6 @@ package gitlab import ( "fmt" - "log" "net/http" "reflect" "testing" @@ -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{ @@ -58,7 +57,7 @@ func TestDeleteEpic(t *testing.T) { _, err := client.Epics.DeleteEpic("7", 8) if err != nil { - log.Fatal(err) + t.Fatal(err) } } @@ -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{{ @@ -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{ @@ -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{ diff --git a/event_parsing_systemhook_test.go b/event_parsing_systemhook_test.go index cc258ea87..b6f5297f4 100644 --- a/event_parsing_systemhook_test.go +++ b/event_parsing_systemhook_test.go @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) } diff --git a/event_parsing_webhook_test.go b/event_parsing_webhook_test.go index da78ede4b..8f8e40b9f 100644 --- a/event_parsing_webhook_test.go +++ b/event_parsing_webhook_test.go @@ -51,7 +51,7 @@ func TestWebhookEventToken(t *testing.T) { } func TestParseBuildHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/build.json") + raw := loadFixture(t, "testdata/webhooks/build.json") parsedEvent, err := ParseWebhook("Build Hook", raw) if err != nil { @@ -85,7 +85,7 @@ func TestParseBuildHook(t *testing.T) { } func TestParseCommitCommentHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/note_commit.json") + raw := loadFixture(t, "testdata/webhooks/note_commit.json") parsedEvent, err := ParseWebhook("Note Hook", raw) if err != nil { @@ -115,7 +115,7 @@ func TestParseCommitCommentHook(t *testing.T) { } func TestParseFeatureFlagHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/feature_flag.json") + raw := loadFixture(t, "testdata/webhooks/feature_flag.json") parsedEvent, err := ParseWebhook("Feature Flag Hook", raw) if err != nil { @@ -161,7 +161,7 @@ func TestParseFeatureFlagHook(t *testing.T) { } func TestParseGroupResourceAccessTokenHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/resource_access_token_group.json") + raw := loadFixture(t, "testdata/webhooks/resource_access_token_group.json") parsedEvent, err := ParseWebhook("Resource Access Token Hook", raw) if err != nil { @@ -181,11 +181,11 @@ func TestParseGroupResourceAccessTokenHook(t *testing.T) { } func TestParseHookWebHook(t *testing.T) { - parsedEvent1, err := ParseHook("Merge Request Hook", loadFixture("testdata/webhooks/merge_request.json")) + parsedEvent1, err := ParseHook("Merge Request Hook", loadFixture(t, "testdata/webhooks/merge_request.json")) if err != nil { t.Errorf("Error parsing build hook: %s", err) } - parsedEvent2, err := ParseWebhook("Merge Request Hook", loadFixture("testdata/webhooks/merge_request.json")) + parsedEvent2, err := ParseWebhook("Merge Request Hook", loadFixture(t, "testdata/webhooks/merge_request.json")) if err != nil { t.Errorf("Error parsing build hook: %s", err) } @@ -193,7 +193,7 @@ func TestParseHookWebHook(t *testing.T) { } func TestParseIssueCommentHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/note_issue.json") + raw := loadFixture(t, "testdata/webhooks/note_issue.json") parsedEvent, err := ParseWebhook("Note Hook", raw) if err != nil { @@ -224,7 +224,7 @@ func TestParseIssueCommentHook(t *testing.T) { } func TestParseIssueHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/issue.json") + raw := loadFixture(t, "testdata/webhooks/issue.json") parsedEvent, err := ParseWebhook("Issue Hook", raw) if err != nil { @@ -263,7 +263,7 @@ func TestParseIssueHook(t *testing.T) { } func TestParseMergeRequestCommentHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/note_merge_request.json") + raw := loadFixture(t, "testdata/webhooks/note_merge_request.json") parsedEvent, err := ParseWebhook("Note Hook", raw) if err != nil { @@ -298,7 +298,7 @@ func TestParseMergeRequestCommentHook(t *testing.T) { } func TestParseMemberHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/member.json") + raw := loadFixture(t, "testdata/webhooks/member.json") parsedEvent, err := ParseWebhook("Member Hook", raw) if err != nil { @@ -316,7 +316,7 @@ func TestParseMemberHook(t *testing.T) { } func TestParseMergeRequestHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/merge_request.json") + raw := loadFixture(t, "testdata/webhooks/merge_request.json") parsedEvent, err := ParseWebhook("Merge Request Hook", raw) if err != nil { @@ -351,7 +351,7 @@ func TestParseMergeRequestHook(t *testing.T) { } func TestParsePipelineHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/pipeline.json") + raw := loadFixture(t, "testdata/webhooks/pipeline.json") parsedEvent, err := ParseWebhook("Pipeline Hook", raw) if err != nil { @@ -385,7 +385,7 @@ func TestParsePipelineHook(t *testing.T) { } func TestParseProjectResourceAccessTokenHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/resource_access_token_project.json") + raw := loadFixture(t, "testdata/webhooks/resource_access_token_project.json") parsedEvent, err := ParseWebhook("Resource Access Token Hook", raw) if err != nil { @@ -405,7 +405,7 @@ func TestParseProjectResourceAccessTokenHook(t *testing.T) { } func TestParsePushHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/push.json") + raw := loadFixture(t, "testdata/webhooks/push.json") parsedEvent, err := ParseWebhook("Push Hook", raw) if err != nil { @@ -439,7 +439,7 @@ func TestParsePushHook(t *testing.T) { } func TestParseReleaseHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/release.json") + raw := loadFixture(t, "testdata/webhooks/release.json") parsedEvent, err := ParseWebhook("Release Hook", raw) if err != nil { @@ -461,7 +461,7 @@ func TestParseReleaseHook(t *testing.T) { } func TestParseServiceWebHook(t *testing.T) { - parsedEvent, err := ParseWebhook("Service Hook", loadFixture("testdata/webhooks/service_merge_request.json")) + parsedEvent, err := ParseWebhook("Service Hook", loadFixture(t, "testdata/webhooks/service_merge_request.json")) if err != nil { t.Errorf("Error parsing service hook merge request: %s", err) } @@ -484,7 +484,7 @@ func TestParseServiceWebHook(t *testing.T) { } func TestParseSnippetCommentHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/note_snippet.json") + raw := loadFixture(t, "testdata/webhooks/note_snippet.json") parsedEvent, err := ParseWebhook("Note Hook", raw) if err != nil { @@ -514,7 +514,7 @@ func TestParseSnippetCommentHook(t *testing.T) { } func TestParseSubGroupHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/subgroup.json") + raw := loadFixture(t, "testdata/webhooks/subgroup.json") parsedEvent, err := ParseWebhook("Subgroup Hook", raw) if err != nil { @@ -532,7 +532,7 @@ func TestParseSubGroupHook(t *testing.T) { } func TestParseTagHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/tag_push.json") + raw := loadFixture(t, "testdata/webhooks/tag_push.json") parsedEvent, err := ParseWebhook("Tag Push Hook", raw) if err != nil { @@ -566,7 +566,7 @@ func TestParseTagHook(t *testing.T) { } func TestParseWikiPageHook(t *testing.T) { - raw := loadFixture("testdata/webhooks/wiki_page.json") + raw := loadFixture(t, "testdata/webhooks/wiki_page.json") parsedEvent, err := ParseWebhook("Wiki Page Hook", raw) if err != nil { diff --git a/event_webhook_types_test.go b/event_webhook_types_test.go index 9d9e128d2..cb6784f9b 100644 --- a/event_webhook_types_test.go +++ b/event_webhook_types_test.go @@ -35,7 +35,7 @@ const ( ) func TestBuildEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/build.json") + jsonObject := loadFixture(t, "testdata/webhooks/build.json") var event *BuildEvent err := json.Unmarshal(jsonObject, &event) @@ -65,7 +65,7 @@ func TestBuildEventUnmarshal(t *testing.T) { } func TestCommitCommentEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/note_commit.json") + jsonObject := loadFixture(t, "testdata/webhooks/note_commit.json") var event *CommitCommentEvent err := json.Unmarshal(jsonObject, &event) @@ -111,7 +111,7 @@ func TestCommitCommentEventUnmarshal(t *testing.T) { } func TestJobEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/job.json") + jsonObject := loadFixture(t, "testdata/webhooks/job.json") var event *JobEvent err := json.Unmarshal(jsonObject, &event) @@ -195,7 +195,7 @@ func TestJobEventUnmarshal(t *testing.T) { } func TestDeploymentEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/deployment.json") + jsonObject := loadFixture(t, "testdata/webhooks/deployment.json") var event *DeploymentEvent err := json.Unmarshal(jsonObject, &event) @@ -245,7 +245,7 @@ func TestDeploymentEventUnmarshal(t *testing.T) { } func TestFeatureFlagEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/feature_flag.json") + jsonObject := loadFixture(t, "testdata/webhooks/feature_flag.json") var event *FeatureFlagEvent err := json.Unmarshal(jsonObject, &event) @@ -291,7 +291,7 @@ func TestFeatureFlagEventUnmarshal(t *testing.T) { } func TestGroupResourceAccessTokenEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/resource_access_token_group.json") + jsonObject := loadFixture(t, "testdata/webhooks/resource_access_token_group.json") var event *GroupResourceAccessTokenEvent err := json.Unmarshal(jsonObject, &event) if err != nil { @@ -326,7 +326,7 @@ func TestGroupResourceAccessTokenEventUnmarshal(t *testing.T) { } func TestIssueCommentEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/note_issue.json") + jsonObject := loadFixture(t, "testdata/webhooks/note_issue.json") var event *IssueCommentEvent err := json.Unmarshal(jsonObject, &event) @@ -403,7 +403,7 @@ func TestIssueCommentEventUnmarshal(t *testing.T) { } func TestIssueEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/issue.json") + jsonObject := loadFixture(t, "testdata/webhooks/issue.json") var event *IssueEvent err := json.Unmarshal(jsonObject, &event) @@ -531,7 +531,7 @@ func TestIssueEventUnmarshal(t *testing.T) { // Generate unit test for MergeCommentEvent func TestMergeCommentEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/note_merge_request.json") + jsonObject := loadFixture(t, "testdata/webhooks/note_merge_request.json") var event *MergeCommentEvent err := json.Unmarshal(jsonObject, &event) @@ -653,7 +653,7 @@ func TestMergeCommentEventUnmarshal(t *testing.T) { } func TestMergeEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/merge_request.json") + jsonObject := loadFixture(t, "testdata/webhooks/merge_request.json") var event *MergeEvent err := json.Unmarshal(jsonObject, &event) @@ -845,7 +845,7 @@ func TestMergeEventUnmarshal(t *testing.T) { } func TestMemberEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/member.json") + jsonObject := loadFixture(t, "testdata/webhooks/member.json") var event *MemberEvent err := json.Unmarshal(jsonObject, &event) @@ -914,7 +914,7 @@ func TestMemberEventUnmarshal(t *testing.T) { } func TestMergeEventUnmarshalFromGroup(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/group_merge_request.json") + jsonObject := loadFixture(t, "testdata/webhooks/group_merge_request.json") var event *MergeEvent err := json.Unmarshal(jsonObject, &event) @@ -968,7 +968,7 @@ func TestMergeEventUnmarshalFromGroup(t *testing.T) { } func TestPipelineEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/pipeline.json") + jsonObject := loadFixture(t, "testdata/webhooks/pipeline.json") var event *PipelineEvent err := json.Unmarshal(jsonObject, &event) @@ -1062,7 +1062,7 @@ func TestPipelineEventUnmarshal(t *testing.T) { } func TestProjectResourceAccessTokenEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/resource_access_token_project.json") + jsonObject := loadFixture(t, "testdata/webhooks/resource_access_token_project.json") var event *ProjectResourceAccessTokenEvent err := json.Unmarshal(jsonObject, &event) if err != nil { @@ -1110,7 +1110,7 @@ func TestProjectResourceAccessTokenEventUnmarshal(t *testing.T) { } func TestPushEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/push.json") + jsonObject := loadFixture(t, "testdata/webhooks/push.json") var event *PushEvent err := json.Unmarshal(jsonObject, &event) if err != nil { @@ -1155,7 +1155,7 @@ func TestPushEventUnmarshal(t *testing.T) { } func TestReleaseEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/release.json") + jsonObject := loadFixture(t, "testdata/webhooks/release.json") var event *ReleaseEvent err := json.Unmarshal(jsonObject, &event) @@ -1197,7 +1197,7 @@ func TestReleaseEventUnmarshal(t *testing.T) { } func TestSubGroupEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/subgroup.json") + jsonObject := loadFixture(t, "testdata/webhooks/subgroup.json") var event *SubGroupEvent err := json.Unmarshal(jsonObject, &event) @@ -1227,7 +1227,7 @@ func TestSubGroupEventUnmarshal(t *testing.T) { } func TestTagEventUnmarshal(t *testing.T) { - jsonObject := loadFixture("testdata/webhooks/tag_push.json") + jsonObject := loadFixture(t, "testdata/webhooks/tag_push.json") var event *TagEvent err := json.Unmarshal(jsonObject, &event) if err != nil { diff --git a/gitlab_test.go b/gitlab_test.go index b07631fd5..5f8722217 100644 --- a/gitlab_test.go +++ b/gitlab_test.go @@ -22,7 +22,6 @@ import ( "errors" "fmt" "io" - "log" "net/http" "net/http/httptest" "os" @@ -250,10 +249,11 @@ func TestRequestWithContext(t *testing.T) { } } -func loadFixture(filePath string) []byte { +func loadFixture(t *testing.T, filePath string) []byte { + t.Helper() content, err := os.ReadFile(filePath) if err != nil { - log.Fatal(err) + t.Fatal(err) } return content diff --git a/group_import_export_test.go b/group_import_export_test.go index 3e3efb171..f9f277b4d 100644 --- a/group_import_export_test.go +++ b/group_import_export_test.go @@ -3,7 +3,6 @@ package gitlab import ( "fmt" "io" - "log" "net/http" "os" "reflect" @@ -58,14 +57,14 @@ func TestGroupImport(t *testing.T) { tmpfile, err := os.CreateTemp(os.TempDir(), "example.*.tar.gz") if err != nil { tmpfile.Close() - log.Fatal(err) + t.Fatal(err) } if _, err := tmpfile.Write(content); err != nil { tmpfile.Close() - log.Fatal(err) + t.Fatal(err) } if err := tmpfile.Close(); err != nil { - log.Fatal(err) + t.Fatal(err) } defer os.Remove(tmpfile.Name()) // clean up diff --git a/group_labels_test.go b/group_labels_test.go index 1fe28e97f..8686231dd 100644 --- a/group_labels_test.go +++ b/group_labels_test.go @@ -18,7 +18,6 @@ package gitlab import ( "fmt" - "log" "net/http" "reflect" "testing" @@ -38,7 +37,7 @@ func TestCreateGroupGroupLabel(t *testing.T) { } label, _, err := client.GroupLabels.CreateGroupLabel("1", l) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &GroupLabel{ID: 1, Name: "MyGroupLabel", Color: "#11FF22"} if !reflect.DeepEqual(want, label) { @@ -55,7 +54,7 @@ func TestDeleteGroupLabelByID(t *testing.T) { _, err := client.GroupLabels.DeleteGroupLabel("1", "1", nil) if err != nil { - log.Fatal(err) + t.Fatal(err) } } @@ -68,7 +67,7 @@ func TestDeleteGroupLabelByName(t *testing.T) { _, err := client.GroupLabels.DeleteGroupLabel("1", "MyGroupLabel", nil) if err != nil { - log.Fatal(err) + t.Fatal(err) } } @@ -89,10 +88,10 @@ func TestUpdateGroupLabel(t *testing.T) { label, resp, err := client.GroupLabels.UpdateGroupLabel("1", "MyGroupLabel", l) if resp == nil { - log.Fatal(err) + t.Fatal(err) } if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &GroupLabel{ID: 1, Name: "NewLabel", Color: "#11FF23", Description: "This is updated label"} @@ -112,7 +111,7 @@ func TestSubscribeToGroupLabel(t *testing.T) { label, _, err := client.GroupLabels.SubscribeToGroupLabel("1", "5") if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &GroupLabel{ID: 5, Name: "kind/bug", Color: "#d9534f", Description: "Bug reported by user", OpenIssuesCount: 1, ClosedIssuesCount: 0, OpenMergeRequestsCount: 1, Subscribed: true} if !reflect.DeepEqual(want, label) { @@ -129,7 +128,7 @@ func TestUnsubscribeFromGroupLabel(t *testing.T) { _, err := client.GroupLabels.UnsubscribeFromGroupLabel("1", "5") if err != nil { - log.Fatal(err) + t.Fatal(err) } } diff --git a/issues_statistics_test.go b/issues_statistics_test.go index 6021bc6c7..295d3bc22 100644 --- a/issues_statistics_test.go +++ b/issues_statistics_test.go @@ -18,7 +18,6 @@ package gitlab import ( "fmt" - "log" "net/http" "reflect" "testing" @@ -40,7 +39,7 @@ func TestGetIssuesStatistics(t *testing.T) { issue, _, err := client.IssuesStatistics.GetIssuesStatistics(opt) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &IssuesStatistics{ @@ -82,7 +81,7 @@ func TestGetGroupIssuesStatistics(t *testing.T) { issue, _, err := client.IssuesStatistics.GetGroupIssuesStatistics(1, opt) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &IssuesStatistics{ @@ -124,7 +123,7 @@ func TestGetProjectIssuesStatistics(t *testing.T) { issue, _, err := client.IssuesStatistics.GetProjectIssuesStatistics(1, opt) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &IssuesStatistics{ diff --git a/issues_test.go b/issues_test.go index 0b73499a4..1822a573b 100644 --- a/issues_test.go +++ b/issues_test.go @@ -18,7 +18,6 @@ package gitlab import ( "fmt" - "log" "net/http" "reflect" "testing" @@ -36,7 +35,7 @@ func TestGetIssue(t *testing.T) { issue, _, err := client.Issues.GetIssue("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Issue{ @@ -62,7 +61,7 @@ func TestGetIssueByID(t *testing.T) { issue, _, err := client.Issues.GetIssueByID(5) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Issue{ @@ -88,7 +87,7 @@ func TestDeleteIssue(t *testing.T) { _, err := client.Issues.DeleteIssue("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } } @@ -105,7 +104,7 @@ func TestReorderIssue(t *testing.T) { issue, _, err := client.Issues.ReorderIssue("1", 5, &opt) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Issue{ @@ -131,7 +130,7 @@ func TestMoveIssue(t *testing.T) { issue, _, err := client.Issues.MoveIssue("1", 11, &MoveIssueOptions{ToProjectID: Ptr(5)}) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Issue{ @@ -157,7 +156,7 @@ func TestMoveIssue(t *testing.T) { }) movedIssue, _, err := client.Issues.GetIssue("1", 11) if err != nil { - log.Fatal(err) + t.Fatal(err) } wantedMovedIssue := &Issue{ @@ -208,7 +207,7 @@ func TestListIssues(t *testing.T) { issues, _, err := client.Issues.ListIssues(listProjectIssue) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*Issue{{ @@ -274,7 +273,7 @@ func TestListIssuesWithLabelDetails(t *testing.T) { issues, _, err := client.Issues.ListIssues(listProjectIssue) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*Issue{{ @@ -318,7 +317,7 @@ func TestListIssuesSearchInTitle(t *testing.T) { issues, _, err := client.Issues.ListIssues(listProjectIssue) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*Issue{{ @@ -356,7 +355,7 @@ func TestListIssuesSearchInDescription(t *testing.T) { issues, _, err := client.Issues.ListIssues(listProjectIssue) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*Issue{{ @@ -401,7 +400,7 @@ func TestListIssuesSearchByIterationID(t *testing.T) { issues, _, err := client.Issues.ListIssues(listProjectIssue) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*Issue{{ @@ -438,7 +437,7 @@ func TestListProjectIssues(t *testing.T) { } issues, _, err := client.Issues.ListProjectIssues("1", listProjectIssue) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*Issue{{ @@ -484,7 +483,7 @@ func TestListProjectIssuesSearchByIterationID(t *testing.T) { issues, _, err := client.Issues.ListProjectIssues(1, listProjectIssue) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*Issue{{ @@ -523,7 +522,7 @@ func TestListGroupIssues(t *testing.T) { issues, _, err := client.Issues.ListGroupIssues("1", listGroupIssue) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*Issue{{ @@ -569,7 +568,7 @@ func TestListGroupIssuesSearchByIterationID(t *testing.T) { issues, _, err := client.Issues.ListGroupIssues(1, listProjectIssue) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*Issue{{ @@ -606,7 +605,7 @@ func TestCreateIssue(t *testing.T) { issue, _, err := client.Issues.CreateIssue("1", createIssueOptions) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Issue{ @@ -636,7 +635,7 @@ func TestUpdateIssue(t *testing.T) { } issue, _, err := client.Issues.UpdateIssue(1, 5, updateIssueOpt) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Issue{ @@ -662,7 +661,7 @@ func TestSubscribeToIssue(t *testing.T) { issue, _, err := client.Issues.SubscribeToIssue("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Issue{ @@ -688,7 +687,7 @@ func TestUnsubscribeFromIssue(t *testing.T) { issue, _, err := client.Issues.UnsubscribeFromIssue("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Issue{ @@ -720,7 +719,7 @@ func TestListMergeRequestsClosingIssue(t *testing.T) { } mergeRequest, _, err := client.Issues.ListMergeRequestsClosingIssue("1", 5, listMergeRequestsClosingIssueOpt) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*MergeRequest{{ID: 1, Title: "test merge one"}, {ID: 2, Title: "test merge two"}} @@ -746,7 +745,7 @@ func TestListMergeRequestsRelatedToIssue(t *testing.T) { } mergeRequest, _, err := client.Issues.ListMergeRequestsRelatedToIssue("1", 5, listMergeRequestsRelatedToIssueOpt) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*MergeRequest{{ID: 1, Title: "test merge one"}, {ID: 2, Title: "test merge two"}} @@ -770,7 +769,7 @@ func TestSetTimeEstimate(t *testing.T) { timeState, _, err := client.Issues.SetTimeEstimate("1", 5, setTimeEstiOpt) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &TimeStats{HumanTimeEstimate: "3h 30m", HumanTotalTimeSpent: "", TimeEstimate: 12600, TotalTimeSpent: 0} @@ -789,7 +788,7 @@ func TestResetTimeEstimate(t *testing.T) { timeState, _, err := client.Issues.ResetTimeEstimate("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &TimeStats{HumanTimeEstimate: "", HumanTotalTimeSpent: "", TimeEstimate: 0, TotalTimeSpent: 0} @@ -814,7 +813,7 @@ func TestAddSpentTime(t *testing.T) { timeState, _, err := client.Issues.AddSpentTime("1", 5, addSpentTimeOpt) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &TimeStats{HumanTimeEstimate: "", HumanTotalTimeSpent: "1h", TimeEstimate: 0, TotalTimeSpent: 3600} @@ -834,7 +833,7 @@ func TestResetSpentTime(t *testing.T) { timeState, _, err := client.Issues.ResetSpentTime("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &TimeStats{HumanTimeEstimate: "", HumanTotalTimeSpent: "", TimeEstimate: 0, TotalTimeSpent: 0} @@ -854,7 +853,7 @@ func TestGetTimeSpent(t *testing.T) { timeState, _, err := client.Issues.GetTimeSpent("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &TimeStats{HumanTimeEstimate: "2h", HumanTotalTimeSpent: "1h", TimeEstimate: 7200, TotalTimeSpent: 3600} @@ -876,7 +875,7 @@ func TestGetIssueParticipants(t *testing.T) { issueParticipants, _, err := client.Issues.GetParticipants("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*BasicUser{ @@ -900,7 +899,7 @@ func TestGetIssueMilestone(t *testing.T) { issue, _, err := client.Issues.GetIssue("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Issue{ @@ -936,7 +935,7 @@ func TestGetIssueGroupMilestone(t *testing.T) { issue, _, err := client.Issues.GetIssue("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Issue{ diff --git a/labels_test.go b/labels_test.go index f6a08f1cc..ac2a85b3b 100644 --- a/labels_test.go +++ b/labels_test.go @@ -18,7 +18,6 @@ package gitlab import ( "fmt" - "log" "net/http" "reflect" "testing" @@ -40,7 +39,7 @@ func TestCreateLabel(t *testing.T) { } label, _, err := client.Labels.CreateLabel("1", l) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Label{ID: 1, Name: "MyLabel", Color: "#11FF22", Priority: 2} if !reflect.DeepEqual(want, label) { @@ -58,7 +57,7 @@ func TestDeleteLabelbyID(t *testing.T) { // Delete label _, err := client.Labels.DeleteLabel("1", "1", nil) if err != nil { - log.Fatal(err) + t.Fatal(err) } } @@ -76,7 +75,7 @@ func TestDeleteLabelbyName(t *testing.T) { _, err := client.Labels.DeleteLabel("1", "MyLabel", label) if err != nil { - log.Fatal(err) + t.Fatal(err) } } @@ -99,10 +98,10 @@ func TestUpdateLabel(t *testing.T) { label, resp, err := client.Labels.UpdateLabel("1", "MyLabel", l) if resp == nil { - log.Fatal(err) + t.Fatal(err) } if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Label{ID: 1, Name: "New Label", Color: "#11FF23", Description: "This is updated label", Priority: 42} @@ -122,7 +121,7 @@ func TestSubscribeToLabel(t *testing.T) { label, _, err := client.Labels.SubscribeToLabel("1", "5") if err != nil { - log.Fatal(err) + t.Fatal(err) } want := &Label{ID: 5, Name: "kind/bug", Color: "#d9534f", Description: "Bug reported by user", OpenIssuesCount: 1, ClosedIssuesCount: 0, OpenMergeRequestsCount: 1, Subscribed: true} if !reflect.DeepEqual(want, label) { @@ -139,7 +138,7 @@ func TestUnsubscribeFromLabel(t *testing.T) { _, err := client.Labels.UnsubscribeFromLabel("1", "5") if err != nil { - log.Fatal(err) + t.Fatal(err) } } diff --git a/merge_requests_test.go b/merge_requests_test.go index eb77362d3..64cdd734a 100644 --- a/merge_requests_test.go +++ b/merge_requests_test.go @@ -19,7 +19,6 @@ package gitlab import ( "encoding/json" "fmt" - "log" "net/http" "reflect" "testing" @@ -346,7 +345,7 @@ func TestGetMergeRequestParticipants(t *testing.T) { mergeRequestParticipants, _, err := client.MergeRequests.GetMergeRequestParticipants("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } want := []*BasicUser{ @@ -371,7 +370,7 @@ func TestGetMergeRequestReviewers(t *testing.T) { mergeRequestReviewers, _, err := client.MergeRequests.GetMergeRequestReviewers("1", 5) if err != nil { - log.Fatal(err) + t.Fatal(err) } createdAt := time.Date(2022, 0o7, 27, 17, 3, 27, 684000000, time.UTC)