forked from kevadesu/forgejo
Add testifylint to lint checks (#4535)
go-require lint is ignored for now Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4535 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: TheFox0x7 <thefox0x7@gmail.com> Co-committed-by: TheFox0x7 <thefox0x7@gmail.com>
This commit is contained in:
parent
94933470cd
commit
4de909747b
504 changed files with 5028 additions and 4680 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/json"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// LoginSource represents an external way for authorizing users.
|
||||
|
@ -45,7 +46,7 @@ func Test_UnwrapLDAPSourceCfg(t *testing.T) {
|
|||
|
||||
// Run the migration
|
||||
if err := UnwrapLDAPSourceCfg(x); err != nil {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -53,7 +54,7 @@ func Test_UnwrapLDAPSourceCfg(t *testing.T) {
|
|||
for start := 0; ; start += batchSize {
|
||||
sources := make([]*LoginSource, 0, batchSize)
|
||||
if err := x.Table("login_source").Limit(batchSize, start).Find(&sources); err != nil {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -66,12 +67,12 @@ func Test_UnwrapLDAPSourceCfg(t *testing.T) {
|
|||
expected := map[string]any{}
|
||||
|
||||
if err := json.Unmarshal([]byte(source.Cfg), &converted); err != nil {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte(source.Expected), &expected); err != nil {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_AddRepoIDForAttachment(t *testing.T) {
|
||||
|
@ -39,7 +40,7 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
|
|||
|
||||
// Run the migration
|
||||
if err := AddRepoIDForAttachment(x); err != nil {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -54,26 +55,26 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
|
|||
|
||||
var issueAttachments []*NewAttachment
|
||||
err := x.Table("attachment").Where("issue_id > 0").Find(&issueAttachments)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
for _, attach := range issueAttachments {
|
||||
assert.Greater(t, attach.RepoID, int64(0))
|
||||
assert.Greater(t, attach.IssueID, int64(0))
|
||||
var issue Issue
|
||||
has, err := x.ID(attach.IssueID).Get(&issue)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
assert.EqualValues(t, attach.RepoID, issue.RepoID)
|
||||
}
|
||||
|
||||
var releaseAttachments []*NewAttachment
|
||||
err = x.Table("attachment").Where("release_id > 0").Find(&releaseAttachments)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
for _, attach := range releaseAttachments {
|
||||
assert.Greater(t, attach.RepoID, int64(0))
|
||||
assert.Greater(t, attach.ReleaseID, int64(0))
|
||||
var release Release
|
||||
has, err := x.ID(attach.ReleaseID).Get(&release)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
assert.EqualValues(t, attach.RepoID, release.RepoID)
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_AddTableCommitStatusIndex(t *testing.T) {
|
||||
|
@ -30,7 +31,7 @@ func Test_AddTableCommitStatusIndex(t *testing.T) {
|
|||
|
||||
// Run the migration
|
||||
if err := AddTableCommitStatusIndex(x); err != nil {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -46,12 +47,12 @@ func Test_AddTableCommitStatusIndex(t *testing.T) {
|
|||
for {
|
||||
indexes := make([]CommitStatusIndex, 0, batchSize)
|
||||
err := x.Table("commit_status_index").Limit(batchSize, start).Find(&indexes)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, idx := range indexes {
|
||||
var maxIndex int
|
||||
has, err := x.SQL("SELECT max(`index`) FROM commit_status WHERE repo_id = ? AND sha = ?", idx.RepoID, idx.SHA).Get(&maxIndex)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
assert.EqualValues(t, maxIndex, idx.MaxIndex)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
|
@ -20,9 +21,9 @@ func TestParseU2FRegistration(t *testing.T) {
|
|||
const testRegRespHex = "0504b174bc49c7ca254b70d2e5c207cee9cf174820ebd77ea3c65508c26da51b657c1cc6b952f8621697936482da0a6d3d3826a59095daf6cd7c03e2e60385d2f6d9402a552dfdb7477ed65fd84133f86196010b2215b57da75d315b7b9e8fe2e3925a6019551bab61d16591659cbaf00b4950f7abfe6660e2e006f76868b772d70c253082013c3081e4a003020102020a47901280001155957352300a06082a8648ce3d0403023017311530130603550403130c476e756262792050696c6f74301e170d3132303831343138323933325a170d3133303831343138323933325a3031312f302d0603550403132650696c6f74476e756262792d302e342e312d34373930313238303030313135353935373335323059301306072a8648ce3d020106082a8648ce3d030107034200048d617e65c9508e64bcc5673ac82a6799da3c1446682c258c463fffdf58dfd2fa3e6c378b53d795c4a4dffb4199edd7862f23abaf0203b4b8911ba0569994e101300a06082a8648ce3d0403020347003044022060cdb6061e9c22262d1aac1d96d8c70829b2366531dda268832cb836bcd30dfa0220631b1459f09e6330055722c8d89b7f48883b9089b88d60d1d9795902b30410df304502201471899bcc3987e62e8202c9b39c33c19033f7340352dba80fcab017db9230e402210082677d673d891933ade6f617e5dbde2e247e70423fd5ad7804a6d3d3961ef871"
|
||||
|
||||
regResp, err := hex.DecodeString(testRegRespHex)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
pubKey, keyHandle, err := parseU2FRegistration(regResp)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "04b174bc49c7ca254b70d2e5c207cee9cf174820ebd77ea3c65508c26da51b657c1cc6b952f8621697936482da0a6d3d3826a59095daf6cd7c03e2e60385d2f6d9", hex.EncodeToString(pubKey.Bytes()))
|
||||
assert.Equal(t, "2a552dfdb7477ed65fd84133f86196010b2215b57da75d315b7b9e8fe2e3925a6019551bab61d16591659cbaf00b4950f7abfe6660e2e006f76868b772d70c25", hex.EncodeToString(keyHandle))
|
||||
}
|
||||
|
@ -71,19 +72,17 @@ func Test_RemigrateU2FCredentials(t *testing.T) {
|
|||
|
||||
// Run the migration
|
||||
if err := RemigrateU2FCredentials(x); err != nil {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
expected := []ExpectedWebauthnCredential{}
|
||||
if err := x.Table("expected_webauthn_credential").Asc("id").Find(&expected); !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err := x.Table("expected_webauthn_credential").Asc("id").Find(&expected)
|
||||
require.NoError(t, err)
|
||||
|
||||
got := []ExpectedWebauthnCredential{}
|
||||
if err := x.Table("webauthn_credential").Select("id, credential_id").Asc("id").Find(&got); !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err = x.Table("webauthn_credential").Select("id, credential_id").Asc("id").Find(&got)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.EqualValues(t, expected, got)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue