Skip to content

Commit 2bd70c7

Browse files
committed
Fix test
1 parent 1482291 commit 2bd70c7

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

models/issues/main_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ import (
99
"testing"
1010

1111
"code.gitea.io/gitea/models/unittest"
12+
"code.gitea.io/gitea/modules/setting"
1213
)
1314

15+
func init() {
16+
setting.SetCustomPathAndConf("", "", "")
17+
setting.LoadForTest()
18+
}
19+
1420
func TestMain(m *testing.M) {
1521
unittest.MainTest(m, filepath.Join("..", ".."),
1622
"reaction.yml",
1723
"user.yml",
24+
"repository.yml",
1825
)
1926
}

models/issues/reaction_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"code.gitea.io/gitea/models/db"
1111
"code.gitea.io/gitea/models/unittest"
12+
repo_model "code.gitea.io/gitea/models/repo"
1213
user_model "code.gitea.io/gitea/models/user"
1314
"code.gitea.io/gitea/modules/setting"
1415

@@ -87,6 +88,7 @@ func TestIssueReactionCount(t *testing.T) {
8788
ghost := user_model.NewGhostUser()
8889

8990
var issueID int64 = 2
91+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
9092

9193
addReaction(t, user1.ID, issueID, 0, "heart")
9294
addReaction(t, user2.ID, issueID, 0, "heart")
@@ -101,6 +103,8 @@ func TestIssueReactionCount(t *testing.T) {
101103
})
102104
assert.NoError(t, err)
103105
assert.Len(t, reactionsList, 7)
106+
_, err = reactionsList.LoadUsers(db.DefaultContext, repo)
107+
assert.NoError(t, err)
104108

105109
reactions := reactionsList.GroupByType()
106110
assert.Len(t, reactions["heart"], 4)

models/migrate_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
repo_model "code.gitea.io/gitea/models/repo"
1313
"code.gitea.io/gitea/models/unittest"
1414
user_model "code.gitea.io/gitea/models/user"
15+
issues_model "code.gitea.io/gitea/models/issues"
1516

1617
"github.com/stretchr/testify/assert"
1718
)
@@ -42,7 +43,7 @@ func assertCreateIssues(t *testing.T, isPull bool) {
4243
label := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
4344
milestone := unittest.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
4445
assert.EqualValues(t, milestone.ID, 1)
45-
reaction := &Reaction{
46+
reaction := &issues_model.Reaction{
4647
Type: "heart",
4748
UserID: owner.ID,
4849
}
@@ -60,7 +61,7 @@ func assertCreateIssues(t *testing.T, isPull bool) {
6061
Poster: owner,
6162
IsClosed: true,
6263
Labels: []*Label{label},
63-
Reactions: []*Reaction{reaction},
64+
Reactions: []*issues_model.Reaction{reaction},
6465
ForeignReference: &foreignreference.ForeignReference{
6566
ForeignIndex: strconv.FormatInt(foreignIndex, 10),
6667
RepoID: repo.ID,
@@ -75,7 +76,7 @@ func assertCreateIssues(t *testing.T, isPull bool) {
7576
err = i.LoadAttributes()
7677
assert.NoError(t, err)
7778
assert.EqualValues(t, strconv.FormatInt(foreignIndex, 10), i.ForeignReference.ForeignIndex)
78-
unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: owner.ID, IssueID: i.ID})
79+
unittest.AssertExistsAndLoadBean(t, &issues_model.Reaction{Type: "heart", UserID: owner.ID, IssueID: i.ID})
7980
}
8081

8182
func TestMigrate_CreateIssuesIsPullFalse(t *testing.T) {
@@ -91,7 +92,7 @@ func TestMigrate_InsertIssueComments(t *testing.T) {
9192
issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
9293
_ = issue.LoadRepo()
9394
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
94-
reaction := &Reaction{
95+
reaction := &issues_model.Reaction{
9596
Type: "heart",
9697
UserID: owner.ID,
9798
}
@@ -101,7 +102,7 @@ func TestMigrate_InsertIssueComments(t *testing.T) {
101102
Poster: owner,
102103
IssueID: issue.ID,
103104
Issue: issue,
104-
Reactions: []*Reaction{reaction},
105+
Reactions: []*issues_model.Reaction{reaction},
105106
}
106107

107108
err := InsertIssueComments([]*Comment{comment})

0 commit comments

Comments
 (0)