loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Replace assert.Fail with assert.FailNow (#27578)

assert.Fail() will continue to execute the code while assert.FailNow()
not. I thought those uses of assert.Fail() should exit immediately.
PS: perhaps it's a good idea to use
[require](https://pkg.go.dev/github.com/stretchr/testify/require)
somewhere because the assert package's default behavior does not exit
when an error occurs, which makes it difficult to find the root error
reason.

authored by

Nanguan Lin and committed by
GitHub
dc040447 dca195e9

+20 -38
+2 -2
models/asymkey/ssh_key_test.go
··· 51 51 if err != nil { 52 52 // Some servers do not support ecdsa format. 53 53 if !strings.Contains(err.Error(), "line 1 too long:") { 54 - assert.Fail(t, "%v", err) 54 + assert.FailNow(t, "%v", err) 55 55 } 56 56 } 57 57 assert.Equal(t, tc.keyType, keyTypeK) ··· 60 60 t.Run("SSHParseKeyNative", func(t *testing.T) { 61 61 keyTypeK, lengthK, err := SSHNativeParsePublicKey(tc.content) 62 62 if err != nil { 63 - assert.Fail(t, "%v", err) 63 + assert.FailNow(t, "%v", err) 64 64 } 65 65 assert.Equal(t, tc.keyType, keyTypeK) 66 66 assert.EqualValues(t, tc.length, lengthK)
+1 -2
models/unittest/consistency.go
··· 47 47 assert.NoError(t, err) 48 48 f := consistencyCheckMap[tb.Name] 49 49 if f == nil { 50 - assert.Fail(t, "unknown bean type: %#v", bean) 51 - return 50 + assert.FailNow(t, "unknown bean type: %#v", bean) 52 51 } 53 52 f(t, bean) 54 53 }
+3 -6
modules/contexttest/context_tests.go
··· 83 83 ctx.Repo = repo 84 84 doer = ctx.Doer 85 85 default: 86 - assert.Fail(t, "context is not *context.Context or *context.APIContext") 87 - return 86 + assert.FailNow(t, "context is not *context.Context or *context.APIContext") 88 87 } 89 88 90 89 repo.Repository = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}) ··· 105 104 case *context.APIContext: 106 105 repo = ctx.Repo 107 106 default: 108 - assert.Fail(t, "context is not *context.Context or *context.APIContext") 109 - return 107 + assert.FailNow(t, "context is not *context.Context or *context.APIContext") 110 108 } 111 109 112 110 gitRepo, err := git.OpenRepository(ctx, repo.Repository.RepoPath()) ··· 130 128 case *context.APIContext: 131 129 ctx.Doer = doer 132 130 default: 133 - assert.Fail(t, "context is not *context.Context or *context.APIContext") 134 - return 131 + assert.FailNow(t, "context is not *context.Context or *context.APIContext") 135 132 } 136 133 } 137 134
+4 -4
modules/git/repo_attribute_test.go
··· 27 27 assert.Equal(t, "linguist-vendored", attr.Attribute) 28 28 assert.Equal(t, "unspecified", attr.Value) 29 29 case <-time.After(100 * time.Millisecond): 30 - assert.Fail(t, "took too long to read an attribute from the list") 30 + assert.FailNow(t, "took too long to read an attribute from the list") 31 31 } 32 32 // Write a second attribute again 33 33 n, err = wr.Write([]byte(testStr)) ··· 41 41 assert.Equal(t, "linguist-vendored", attr.Attribute) 42 42 assert.Equal(t, "unspecified", attr.Value) 43 43 case <-time.After(100 * time.Millisecond): 44 - assert.Fail(t, "took too long to read an attribute from the list") 44 + assert.FailNow(t, "took too long to read an attribute from the list") 45 45 } 46 46 47 47 // Write a partial attribute ··· 52 52 53 53 select { 54 54 case <-wr.ReadAttribute(): 55 - assert.Fail(t, "There should not be an attribute ready to read") 55 + assert.FailNow(t, "There should not be an attribute ready to read") 56 56 case <-time.After(100 * time.Millisecond): 57 57 } 58 58 _, err = wr.Write([]byte("attribute\x00")) 59 59 assert.NoError(t, err) 60 60 select { 61 61 case <-wr.ReadAttribute(): 62 - assert.Fail(t, "There should not be an attribute ready to read") 62 + assert.FailNow(t, "There should not be an attribute ready to read") 63 63 case <-time.After(100 * time.Millisecond): 64 64 } 65 65
-2
modules/git/repo_tag_test.go
··· 71 71 if lTag == nil { 72 72 assert.NotNil(t, lTag) 73 73 assert.FailNow(t, "nil lTag: %s", lTagName) 74 - return 75 74 } 76 75 assert.EqualValues(t, lTagName, lTag.Name) 77 76 assert.EqualValues(t, lTagCommitID, lTag.ID.String()) ··· 105 104 if aTag == nil { 106 105 assert.NotNil(t, aTag) 107 106 assert.FailNow(t, "nil aTag: %s", aTagName) 108 - return 109 107 } 110 108 assert.EqualValues(t, aTagName, aTag.Name) 111 109 assert.EqualValues(t, aTagID, aTag.ID.String())
+2 -4
modules/indexer/code/indexer_test.go
··· 96 96 idx := bleve.NewIndexer(dir) 97 97 _, err := idx.Init(context.Background()) 98 98 if err != nil { 99 - assert.Fail(t, "Unable to create bleve indexer Error: %v", err) 100 99 if idx != nil { 101 100 idx.Close() 102 101 } 103 - return 102 + assert.FailNow(t, "Unable to create bleve indexer Error: %v", err) 104 103 } 105 104 defer idx.Close() 106 105 ··· 118 117 119 118 indexer := elasticsearch.NewIndexer(u, "gitea_codes") 120 119 if _, err := indexer.Init(context.Background()); err != nil { 121 - assert.Fail(t, "Unable to init ES indexer Error: %v", err) 122 120 if indexer != nil { 123 121 indexer.Close() 124 122 } 125 - return 123 + assert.FailNow(t, "Unable to init ES indexer Error: %v", err) 126 124 } 127 125 128 126 defer indexer.Close()
+2 -2
modules/process/manager_test.go
··· 50 50 select { 51 51 case <-ctx.Done(): 52 52 default: 53 - assert.Fail(t, "Cancel should cancel the provided context") 53 + assert.FailNow(t, "Cancel should cancel the provided context") 54 54 } 55 55 finished() 56 56 ··· 62 62 select { 63 63 case <-ctx.Done(): 64 64 default: 65 - assert.Fail(t, "Cancel should cancel the provided context") 65 + assert.FailNow(t, "Cancel should cancel the provided context") 66 66 } 67 67 finished() 68 68 }
+1 -1
services/pull/check_test.go
··· 54 54 case id := <-idChan: 55 55 assert.EqualValues(t, pr.ID, id) 56 56 case <-time.After(time.Second): 57 - assert.Fail(t, "Timeout: nothing was added to pullRequestQueue") 57 + assert.FailNow(t, "Timeout: nothing was added to pullRequestQueue") 58 58 } 59 59 60 60 has, err = prPatchCheckerQueue.Has(strconv.FormatInt(pr.ID, 10))
+1 -1
tests/integration/api_packages_conan_test.go
··· 296 296 297 297 assert.Equal(t, int64(len(contentConaninfo)), pb.Size) 298 298 } else { 299 - assert.Fail(t, "unknown file: %s", pf.Name) 299 + assert.FailNow(t, "unknown file: %s", pf.Name) 300 300 } 301 301 } 302 302 })
+1 -1
tests/integration/api_packages_container_test.go
··· 349 349 assert.Equal(t, "application/vnd.docker.image.rootfs.diff.tar.gzip", pfd.Properties.GetByName(container_module.PropertyMediaType)) 350 350 assert.Equal(t, blobDigest, pfd.Properties.GetByName(container_module.PropertyDigest)) 351 351 default: 352 - assert.Fail(t, "unknown file: %s", pfd.File.Name) 352 + assert.FailNow(t, "unknown file: %s", pfd.File.Name) 353 353 } 354 354 } 355 355
+1 -1
tests/integration/api_packages_nuget_test.go
··· 326 326 assert.Equal(t, nuget_module.PropertySymbolID, pps[0].Name) 327 327 assert.Equal(t, symbolID, pps[0].Value) 328 328 default: 329 - assert.Fail(t, "unexpected file: %v", pf.Name) 329 + assert.FailNow(t, "unexpected file: %v", pf.Name) 330 330 } 331 331 } 332 332
+1 -1
tests/integration/api_repo_test.go
··· 368 368 case "You can not import from disallowed hosts.": 369 369 assert.EqualValues(t, "private-ip", testCase.repoName) 370 370 default: 371 - assert.Failf(t, "unexpected error '%v' on url '%s'", respJSON["message"], testCase.cloneURL) 371 + assert.FailNow(t, "unexpected error '%v' on url '%s'", respJSON["message"], testCase.cloneURL) 372 372 } 373 373 } else { 374 374 assert.EqualValues(t, testCase.expectedStatus, resp.Code)
+1 -2
tests/integration/api_token_test.go
··· 483 483 } else if minRequiredLevel == auth_model.Write { 484 484 unauthorizedLevel = auth_model.Read 485 485 } else { 486 - assert.Failf(t, "Invalid test case", "Unknown access token scope level: %v", minRequiredLevel) 487 - return 486 + assert.FailNow(t, "Invalid test case: Unknown access token scope level: %v", minRequiredLevel) 488 487 } 489 488 } 490 489
-9
tests/integration/gpg_git_test.go
··· 106 106 assert.NotNil(t, response.Verification) 107 107 if response.Verification == nil { 108 108 assert.FailNow(t, "no verification provided with response! %v", response) 109 - return 110 109 } 111 110 assert.True(t, response.Verification.Verified) 112 111 if !response.Verification.Verified { 113 112 t.FailNow() 114 - return 115 113 } 116 114 assert.Equal(t, "gitea@fake.local", response.Verification.Signer.Email) 117 115 })) ··· 120 118 assert.NotNil(t, response.Verification) 121 119 if response.Verification == nil { 122 120 assert.FailNow(t, "no verification provided with response! %v", response) 123 - return 124 121 } 125 122 assert.True(t, response.Verification.Verified) 126 123 if !response.Verification.Verified { 127 124 t.FailNow() 128 - return 129 125 } 130 126 assert.Equal(t, "gitea@fake.local", response.Verification.Signer.Email) 131 127 })) ··· 140 136 assert.NotNil(t, response.Verification) 141 137 if response.Verification == nil { 142 138 assert.FailNow(t, "no verification provided with response! %v", response) 143 - return 144 139 } 145 140 assert.True(t, response.Verification.Verified) 146 141 if !response.Verification.Verified { 147 142 t.FailNow() 148 - return 149 143 } 150 144 assert.Equal(t, "gitea@fake.local", response.Verification.Signer.Email) 151 145 })) ··· 160 154 assert.NotNil(t, branch.Commit) 161 155 if branch.Commit == nil { 162 156 assert.FailNow(t, "no commit provided with branch! %v", branch) 163 - return 164 157 } 165 158 assert.NotNil(t, branch.Commit.Verification) 166 159 if branch.Commit.Verification == nil { 167 160 assert.FailNow(t, "no verification provided with branch commit! %v", branch.Commit) 168 - return 169 161 } 170 162 assert.True(t, branch.Commit.Verification.Verified) 171 163 if !branch.Commit.Verification.Verified { 172 164 t.FailNow() 173 - return 174 165 } 175 166 assert.Equal(t, "gitea@fake.local", branch.Commit.Verification.Signer.Email) 176 167 }))