Skip to content

Commit 5451345

Browse files
authored
prefer NoError/Error over Nil/NotNil (#12271)
1 parent b609a25 commit 5451345

11 files changed

+34
-34
lines changed

integrations/repofiles_delete_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func testDeleteRepoFile(t *testing.T, u *url.URL) {
8080

8181
t.Run("Delete README.md file", func(t *testing.T) {
8282
fileResponse, err := repofiles.DeleteRepoFile(repo, doer, opts)
83-
assert.Nil(t, err)
83+
assert.NoError(t, err)
8484
expectedFileResponse := getExpectedDeleteFileResponse(u)
8585
assert.NotNil(t, fileResponse)
8686
assert.Nil(t, fileResponse.Content)
@@ -122,7 +122,7 @@ func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) {
122122

123123
t.Run("Delete README.md without Branch Name", func(t *testing.T) {
124124
fileResponse, err := repofiles.DeleteRepoFile(repo, doer, opts)
125-
assert.Nil(t, err)
125+
assert.NoError(t, err)
126126
expectedFileResponse := getExpectedDeleteFileResponse(u)
127127
assert.NotNil(t, fileResponse)
128128
assert.Nil(t, fileResponse.Content)

integrations/repofiles_update_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) {
201201
fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts)
202202

203203
// asserts
204-
assert.Nil(t, err)
204+
assert.NoError(t, err)
205205
gitRepo, _ := git.OpenRepository(repo.RepoPath())
206206
defer gitRepo.Close()
207207

@@ -237,7 +237,7 @@ func TestCreateOrUpdateRepoFileForUpdate(t *testing.T) {
237237
fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts)
238238

239239
// asserts
240-
assert.Nil(t, err)
240+
assert.NoError(t, err)
241241
gitRepo, _ := git.OpenRepository(repo.RepoPath())
242242
defer gitRepo.Close()
243243

@@ -272,7 +272,7 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) {
272272
fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts)
273273

274274
// asserts
275-
assert.Nil(t, err)
275+
assert.NoError(t, err)
276276
gitRepo, _ := git.OpenRepository(repo.RepoPath())
277277
defer gitRepo.Close()
278278

@@ -287,7 +287,7 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) {
287287
t.Fatalf("expected git.ErrNotExist, got:%v", err)
288288
}
289289
toEntry, err := commit.GetTreeEntryByPath(opts.TreePath)
290-
assert.Nil(t, err)
290+
assert.NoError(t, err)
291291
assert.Nil(t, fromEntry) // Should no longer exist here
292292
assert.NotNil(t, toEntry) // Should exist here
293293
// assert SHA has remained the same but paths use the new file name
@@ -322,7 +322,7 @@ func TestCreateOrUpdateRepoFileWithoutBranchNames(t *testing.T) {
322322
fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts)
323323

324324
// asserts
325-
assert.Nil(t, err)
325+
assert.NoError(t, err)
326326
gitRepo, _ := git.OpenRepository(repo.RepoPath())
327327
defer gitRepo.Close()
328328

modules/repofiles/blob_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ func TestGetBlobBySHA(t *testing.T) {
3535
SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
3636
Size: 180,
3737
}
38-
assert.Nil(t, err)
38+
assert.NoError(t, err)
3939
assert.Equal(t, expectedGBR, gbr)
4040
}

modules/repofiles/content_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ func TestGetContents(t *testing.T) {
6666
t.Run("Get README.md contents with GetContents()", func(t *testing.T) {
6767
fileContentResponse, err := GetContents(ctx.Repo.Repository, treePath, ref, false)
6868
assert.EqualValues(t, expectedContentsResponse, fileContentResponse)
69-
assert.Nil(t, err)
69+
assert.NoError(t, err)
7070
})
7171

7272
t.Run("Get REAMDE.md contents with ref as empty string (should then use the repo's default branch) with GetContents()", func(t *testing.T) {
7373
fileContentResponse, err := GetContents(ctx.Repo.Repository, treePath, "", false)
7474
assert.EqualValues(t, expectedContentsResponse, fileContentResponse)
75-
assert.Nil(t, err)
75+
assert.NoError(t, err)
7676
})
7777
}
7878

@@ -101,13 +101,13 @@ func TestGetContentsOrListForDir(t *testing.T) {
101101
t.Run("Get root dir contents with GetContentsOrList()", func(t *testing.T) {
102102
fileContentResponse, err := GetContentsOrList(ctx.Repo.Repository, treePath, ref)
103103
assert.EqualValues(t, expectedContentsListResponse, fileContentResponse)
104-
assert.Nil(t, err)
104+
assert.NoError(t, err)
105105
})
106106

107107
t.Run("Get root dir contents with ref as empty string (should then use the repo's default branch) with GetContentsOrList()", func(t *testing.T) {
108108
fileContentResponse, err := GetContentsOrList(ctx.Repo.Repository, treePath, "")
109109
assert.EqualValues(t, expectedContentsListResponse, fileContentResponse)
110-
assert.Nil(t, err)
110+
assert.NoError(t, err)
111111
})
112112
}
113113

@@ -129,13 +129,13 @@ func TestGetContentsOrListForFile(t *testing.T) {
129129
t.Run("Get README.md contents with GetContentsOrList()", func(t *testing.T) {
130130
fileContentResponse, err := GetContentsOrList(ctx.Repo.Repository, treePath, ref)
131131
assert.EqualValues(t, expectedContentsResponse, fileContentResponse)
132-
assert.Nil(t, err)
132+
assert.NoError(t, err)
133133
})
134134

135135
t.Run("Get REAMDE.md contents with ref as empty string (should then use the repo's default branch) with GetContentsOrList()", func(t *testing.T) {
136136
fileContentResponse, err := GetContentsOrList(ctx.Repo.Repository, treePath, "")
137137
assert.EqualValues(t, expectedContentsResponse, fileContentResponse)
138-
assert.Nil(t, err)
138+
assert.NoError(t, err)
139139
})
140140
}
141141

modules/repofiles/diff_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ func TestGetDiffPreview(t *testing.T) {
113113

114114
t.Run("with given branch", func(t *testing.T) {
115115
diff, err := GetDiffPreview(ctx.Repo.Repository, branch, treePath, content)
116-
assert.Nil(t, err)
116+
assert.NoError(t, err)
117117
assert.EqualValues(t, expectedDiff, diff)
118118
})
119119

120120
t.Run("empty branch, same results", func(t *testing.T) {
121121
diff, err := GetDiffPreview(ctx.Repo.Repository, "", treePath, content)
122-
assert.Nil(t, err)
122+
assert.NoError(t, err)
123123
assert.EqualValues(t, expectedDiff, diff)
124124
})
125125
}

modules/repofiles/file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ func TestGetFileResponseFromCommit(t *testing.T) {
9999
expectedFileResponse := getExpectedFileResponse()
100100

101101
fileResponse, err := GetFileResponseFromCommit(repo, commit, branch, treePath)
102-
assert.Nil(t, err)
102+
assert.NoError(t, err)
103103
assert.EqualValues(t, expectedFileResponse, fileResponse)
104104
}

modules/repofiles/tree_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestGetTreeBySHA(t *testing.T) {
3030
ctx.SetParams(":sha", sha)
3131

3232
tree, err := GetTreeBySHA(ctx.Repo.Repository, ctx.Params(":sha"), page, perPage, true)
33-
assert.Nil(t, err)
33+
assert.NoError(t, err)
3434
expectedTree := &api.GitTreeResponse{
3535
SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
3636
URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/trees/65f1bf27bc3bf70f64657658635e66094edbcb4d",

modules/webhook/dingtalk_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ func TestGetDingTalkIssuesPayload(t *testing.T) {
1717

1818
p.Action = api.HookIssueOpened
1919
pl, err := getDingtalkIssuesPayload(p)
20-
require.Nil(t, err)
20+
require.NoError(t, err)
2121
require.NotNil(t, pl)
2222
assert.Equal(t, "#2 crash", pl.ActionCard.Title)
2323
assert.Equal(t, "[test/repo] Issue opened: #2 crash by user1\r\n\r\n", pl.ActionCard.Text)
2424

2525
p.Action = api.HookIssueClosed
2626
pl, err = getDingtalkIssuesPayload(p)
27-
require.Nil(t, err)
27+
require.NoError(t, err)
2828
require.NotNil(t, pl)
2929
assert.Equal(t, "#2 crash", pl.ActionCard.Title)
3030
assert.Equal(t, "[test/repo] Issue closed: #2 crash by user1\r\n\r\n", pl.ActionCard.Text)

modules/webhook/matrix_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ func TestMatrixIssuesPayloadOpened(t *testing.T) {
2020

2121
p.Action = api.HookIssueOpened
2222
pl, err := getMatrixIssuesPayload(p, sl)
23-
require.Nil(t, err)
23+
require.NoError(t, err)
2424
require.NotNil(t, pl)
2525
assert.Equal(t, "[[test/repo](http://localhost:3000/test/repo)] Issue opened: [#2 crash](http://localhost:3000/test/repo/issues/2) by [user1](https://try.gitea.io/user1)", pl.Body)
2626
assert.Equal(t, "[<a href=\"http://localhost:3000/test/repo\">test/repo</a>] Issue opened: <a href=\"http://localhost:3000/test/repo/issues/2\">#2 crash</a> by <a href=\"https://try.gitea.io/user1\">user1</a>", pl.FormattedBody)
2727

2828
p.Action = api.HookIssueClosed
2929
pl, err = getMatrixIssuesPayload(p, sl)
30-
require.Nil(t, err)
30+
require.NoError(t, err)
3131
require.NotNil(t, pl)
3232
assert.Equal(t, "[[test/repo](http://localhost:3000/test/repo)] Issue closed: [#2 crash](http://localhost:3000/test/repo/issues/2) by [user1](https://try.gitea.io/user1)", pl.Body)
3333
assert.Equal(t, "[<a href=\"http://localhost:3000/test/repo\">test/repo</a>] Issue closed: <a href=\"http://localhost:3000/test/repo/issues/2\">#2 crash</a> by <a href=\"https://try.gitea.io/user1\">user1</a>", pl.FormattedBody)
@@ -39,7 +39,7 @@ func TestMatrixIssueCommentPayload(t *testing.T) {
3939
sl := &MatrixMeta{}
4040

4141
pl, err := getMatrixIssueCommentPayload(p, sl)
42-
require.Nil(t, err)
42+
require.NoError(t, err)
4343
require.NotNil(t, pl)
4444

4545
assert.Equal(t, "[[test/repo](http://localhost:3000/test/repo)] New comment on issue [#2 crash](http://localhost:3000/test/repo/issues/2) by [user1](https://try.gitea.io/user1)", pl.Body)
@@ -52,7 +52,7 @@ func TestMatrixPullRequestCommentPayload(t *testing.T) {
5252
sl := &MatrixMeta{}
5353

5454
pl, err := getMatrixIssueCommentPayload(p, sl)
55-
require.Nil(t, err)
55+
require.NoError(t, err)
5656
require.NotNil(t, pl)
5757

5858
assert.Equal(t, "[[test/repo](http://localhost:3000/test/repo)] New comment on pull request [#2 Fix bug](http://localhost:3000/test/repo/pulls/2) by [user1](https://try.gitea.io/user1)", pl.Body)
@@ -65,7 +65,7 @@ func TestMatrixReleasePayload(t *testing.T) {
6565
sl := &MatrixMeta{}
6666

6767
pl, err := getMatrixReleasePayload(p, sl)
68-
require.Nil(t, err)
68+
require.NoError(t, err)
6969
require.NotNil(t, pl)
7070

7171
assert.Equal(t, "[[test/repo](http://localhost:3000/test/repo)] Release created: [v1.0](http://localhost:3000/test/repo/src/v1.0) by [user1](https://try.gitea.io/user1)", pl.Body)
@@ -78,7 +78,7 @@ func TestMatrixPullRequestPayload(t *testing.T) {
7878
sl := &MatrixMeta{}
7979

8080
pl, err := getMatrixPullRequestPayload(p, sl)
81-
require.Nil(t, err)
81+
require.NoError(t, err)
8282
require.NotNil(t, pl)
8383

8484
assert.Equal(t, "[[test/repo](http://localhost:3000/test/repo)] Pull request opened: [#2 Fix bug](http://localhost:3000/test/repo/pulls/12) by [user1](https://try.gitea.io/user1)", pl.Body)
@@ -148,7 +148,7 @@ func TestMatrixHookRequest(t *testing.T) {
148148
}`
149149

150150
req, err := getMatrixHookRequest(h)
151-
require.Nil(t, err)
151+
require.NoError(t, err)
152152
require.NotNil(t, req)
153153

154154
assert.Equal(t, "Bearer dummy_access_token", req.Header.Get("Authorization"))

modules/webhook/slack_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ func TestSlackIssuesPayloadOpened(t *testing.T) {
2020

2121
p.Action = api.HookIssueOpened
2222
pl, err := getSlackIssuesPayload(p, sl)
23-
require.Nil(t, err)
23+
require.NoError(t, err)
2424
require.NotNil(t, pl)
2525
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Issue opened: <http://localhost:3000/test/repo/issues/2|#2 crash> by <https://try.gitea.io/user1|user1>", pl.Text)
2626

2727
p.Action = api.HookIssueClosed
2828
pl, err = getSlackIssuesPayload(p, sl)
29-
require.Nil(t, err)
29+
require.NoError(t, err)
3030
require.NotNil(t, pl)
3131
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Issue closed: <http://localhost:3000/test/repo/issues/2|#2 crash> by <https://try.gitea.io/user1|user1>", pl.Text)
3232
}
@@ -39,7 +39,7 @@ func TestSlackIssueCommentPayload(t *testing.T) {
3939
}
4040

4141
pl, err := getSlackIssueCommentPayload(p, sl)
42-
require.Nil(t, err)
42+
require.NoError(t, err)
4343
require.NotNil(t, pl)
4444

4545
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] New comment on issue <http://localhost:3000/test/repo/issues/2|#2 crash> by <https://try.gitea.io/user1|user1>", pl.Text)
@@ -53,7 +53,7 @@ func TestSlackPullRequestCommentPayload(t *testing.T) {
5353
}
5454

5555
pl, err := getSlackIssueCommentPayload(p, sl)
56-
require.Nil(t, err)
56+
require.NoError(t, err)
5757
require.NotNil(t, pl)
5858

5959
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] New comment on pull request <http://localhost:3000/test/repo/pulls/2|#2 Fix bug> by <https://try.gitea.io/user1|user1>", pl.Text)
@@ -67,7 +67,7 @@ func TestSlackReleasePayload(t *testing.T) {
6767
}
6868

6969
pl, err := getSlackReleasePayload(p, sl)
70-
require.Nil(t, err)
70+
require.NoError(t, err)
7171
require.NotNil(t, pl)
7272

7373
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Release created: <http://localhost:3000/test/repo/src/v1.0|v1.0> by <https://try.gitea.io/user1|user1>", pl.Text)
@@ -81,7 +81,7 @@ func TestSlackPullRequestPayload(t *testing.T) {
8181
}
8282

8383
pl, err := getSlackPullRequestPayload(p, sl)
84-
require.Nil(t, err)
84+
require.NoError(t, err)
8585
require.NotNil(t, pl)
8686

8787
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Pull request opened: <http://localhost:3000/test/repo/pulls/12|#2 Fix bug> by <https://try.gitea.io/user1|user1>", pl.Text)

modules/webhook/telegram_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestGetTelegramIssuesPayload(t *testing.T) {
1717
p.Action = api.HookIssueClosed
1818

1919
pl, err := getTelegramIssuesPayload(p)
20-
require.Nil(t, err)
20+
require.NoError(t, err)
2121
require.NotNil(t, pl)
2222

2323
assert.Equal(t, "[<a href=\"http://localhost:3000/test/repo\">test/repo</a>] Issue closed: <a href=\"http://localhost:3000/test/repo/issues/2\">#2 crash</a> by <a href=\"https://try.gitea.io/user1\">user1</a>\n\n", pl.Message)

0 commit comments

Comments
 (0)