diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-11-12 22:36:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-12 22:36:47 +0800 |
commit | df64fa486555de6f403a795fd16c2e9e1d59e535 (patch) | |
tree | b899e9b9e5d57409b1bf0e3afbd606b6a3900235 /routers/web/user | |
parent | 7f802631c54d2e91301158380b273b872d62bd80 (diff) | |
download | gitea-df64fa486555de6f403a795fd16c2e9e1d59e535.tar.gz gitea-df64fa486555de6f403a795fd16c2e9e1d59e535.zip |
Decouple unit test code from business code (#17623)
Diffstat (limited to 'routers/web/user')
-rw-r--r-- | routers/web/user/home_test.go | 12 | ||||
-rw-r--r-- | routers/web/user/main_test.go | 4 | ||||
-rw-r--r-- | routers/web/user/oauth_test.go | 3 | ||||
-rw-r--r-- | routers/web/user/setting/account_test.go | 4 | ||||
-rw-r--r-- | routers/web/user/setting/main_test.go | 4 |
5 files changed, 14 insertions, 13 deletions
diff --git a/routers/web/user/home_test.go b/routers/web/user/home_test.go index daf473b270..cd599abd04 100644 --- a/routers/web/user/home_test.go +++ b/routers/web/user/home_test.go @@ -9,7 +9,7 @@ import ( "testing" "code.gitea.io/gitea/models" - "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/test" @@ -19,7 +19,7 @@ import ( func TestArchivedIssues(t *testing.T) { // Arrange setting.UI.IssuePagingNum = 1 - assert.NoError(t, db.LoadFixtures()) + assert.NoError(t, unittest.LoadFixtures()) ctx := test.MockContext(t, "issues") test.LoadUser(t, ctx, 30) @@ -52,7 +52,7 @@ func TestArchivedIssues(t *testing.T) { func TestIssues(t *testing.T) { setting.UI.IssuePagingNum = 1 - assert.NoError(t, db.LoadFixtures()) + assert.NoError(t, unittest.LoadFixtures()) ctx := test.MockContext(t, "issues") test.LoadUser(t, ctx, 2) @@ -68,7 +68,7 @@ func TestIssues(t *testing.T) { func TestPulls(t *testing.T) { setting.UI.IssuePagingNum = 20 - assert.NoError(t, db.LoadFixtures()) + assert.NoError(t, unittest.LoadFixtures()) ctx := test.MockContext(t, "pulls") test.LoadUser(t, ctx, 2) @@ -81,7 +81,7 @@ func TestPulls(t *testing.T) { func TestMilestones(t *testing.T) { setting.UI.IssuePagingNum = 1 - assert.NoError(t, db.LoadFixtures()) + assert.NoError(t, unittest.LoadFixtures()) ctx := test.MockContext(t, "milestones") test.LoadUser(t, ctx, 2) @@ -100,7 +100,7 @@ func TestMilestones(t *testing.T) { func TestMilestonesForSpecificRepo(t *testing.T) { setting.UI.IssuePagingNum = 1 - assert.NoError(t, db.LoadFixtures()) + assert.NoError(t, unittest.LoadFixtures()) ctx := test.MockContext(t, "milestones") test.LoadUser(t, ctx, 2) diff --git a/routers/web/user/main_test.go b/routers/web/user/main_test.go index 272e4b8b21..77b48d89fb 100644 --- a/routers/web/user/main_test.go +++ b/routers/web/user/main_test.go @@ -8,9 +8,9 @@ import ( "path/filepath" "testing" - "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - db.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, filepath.Join("..", "..", "..")) } diff --git a/routers/web/user/oauth_test.go b/routers/web/user/oauth_test.go index 27d339b778..e0c1bf4e77 100644 --- a/routers/web/user/oauth_test.go +++ b/routers/web/user/oauth_test.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/login" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/services/auth/source/oauth2" "github.com/golang-jwt/jwt" @@ -41,7 +42,7 @@ func createAndParseToken(t *testing.T, grant *login.OAuth2Grant) *oauth2.OIDCTok } func TestNewAccessTokenResponse_OIDCToken(t *testing.T) { - assert.NoError(t, db.PrepareTestDatabase()) + assert.NoError(t, unittest.PrepareTestDatabase()) grants, err := login.GetOAuth2GrantsByUserID(3) assert.NoError(t, err) diff --git a/routers/web/user/setting/account_test.go b/routers/web/user/setting/account_test.go index bfb7ac4872..cd5c77795e 100644 --- a/routers/web/user/setting/account_test.go +++ b/routers/web/user/setting/account_test.go @@ -8,7 +8,7 @@ import ( "net/http" "testing" - "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/web" @@ -81,7 +81,7 @@ func TestChangePassword(t *testing.T) { PasswordComplexity: pcLU, }, } { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user/settings/security") test.LoadUser(t, ctx, 2) test.LoadRepo(t, ctx, 1) diff --git a/routers/web/user/setting/main_test.go b/routers/web/user/setting/main_test.go index a0fbe55ee1..b6ed7f5b18 100644 --- a/routers/web/user/setting/main_test.go +++ b/routers/web/user/setting/main_test.go @@ -8,9 +8,9 @@ import ( "path/filepath" "testing" - "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - db.MainTest(m, filepath.Join("..", "..", "..", "..")) + unittest.MainTest(m, filepath.Join("..", "..", "..", "..")) } |