mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Decouple unit test code from business code (#17623)
This commit is contained in:
@@ -8,12 +8,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetEmailAddresses(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
emails, _ := GetEmailAddresses(int64(1))
|
||||
if assert.Len(t, emails, 3) {
|
||||
@@ -30,7 +31,7 @@ func TestGetEmailAddresses(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIsEmailUsed(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
isExist, _ := IsEmailUsed(db.DefaultContext, "")
|
||||
assert.True(t, isExist)
|
||||
@@ -41,7 +42,7 @@ func TestIsEmailUsed(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddEmailAddress(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
assert.NoError(t, AddEmailAddress(&EmailAddress{
|
||||
Email: "user1234567890@example.com",
|
||||
@@ -60,7 +61,7 @@ func TestAddEmailAddress(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddEmailAddresses(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
// insert multiple email address
|
||||
emails := make([]*EmailAddress, 2)
|
||||
@@ -83,7 +84,7 @@ func TestAddEmailAddresses(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteEmailAddress(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
assert.NoError(t, DeleteEmailAddress(&EmailAddress{
|
||||
UID: int64(1),
|
||||
@@ -108,7 +109,7 @@ func TestDeleteEmailAddress(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteEmailAddresses(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
// delete multiple email address
|
||||
emails := make([]*EmailAddress, 2)
|
||||
|
@@ -8,11 +8,11 @@ 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("..", ".."),
|
||||
"email_address.yml",
|
||||
"user_redirect.yml",
|
||||
)
|
||||
|
@@ -7,12 +7,13 @@ package user
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLookupUserRedirect(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
userID, err := LookupUserRedirect("olduser1")
|
||||
assert.NoError(t, err)
|
||||
|
Reference in New Issue
Block a user