mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
test: consolidate Go tests (#39962)
Consolidate all Go tests. Coverage is identical to before. Go tests are around 5% faster while being 7% smaller. No non-test code is touched.
This commit is contained in:
1 parent
ce7364e215
commit
8abda62312
388 files changed
+18410
-29561
No files matched your search
@@ -16,9 +16,9 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestToCommitMeta(t *testing.T) {
|
||||
func TestToCommitMetaAndTree(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
sha1 := git.Sha1ObjectFormat
|
||||
signature := &git.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)}
|
||||
tag := &git.Tag{
|
||||
@@ -30,20 +30,15 @@ func TestToCommitMeta(t *testing.T) {
|
||||
CommitMessage: git.CommitMessage{MessageRaw: "Test Message"},
|
||||
}
|
||||
|
||||
commitMeta := ToCommitMeta(headRepo, tag)
|
||||
commitMeta := ToCommitMeta(repo, tag)
|
||||
|
||||
assert.NotNil(t, commitMeta)
|
||||
assert.Equal(t, &api.CommitMeta{
|
||||
SHA: sha1.EmptyObjectID().String(),
|
||||
URL: headRepo.APIURL() + "/git/commits/" + sha1.EmptyObjectID().String(),
|
||||
URL: repo.APIURL() + "/git/commits/" + sha1.EmptyObjectID().String(),
|
||||
Created: time.Unix(0, 0),
|
||||
}, commitMeta)
|
||||
}
|
||||
|
||||
func TestToCommitTree(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
signature := &git.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)}
|
||||
commit := &git.Commit{
|
||||
ID: git.MustIDFromString("65f1bf27bc3bf70f64657658635e66094edbcb4d"),
|
||||
TreeID: git.MustIDFromString("2a2f1d4670728a2e10049e345bd7a276468beab6"),
|
||||
|
||||
@@ -96,49 +96,38 @@ func TestToNotificationThread(t *testing.T) {
|
||||
assert.True(t, thread.Pinned)
|
||||
})
|
||||
|
||||
t.Run("merged pull request returns merged state", func(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
issueID int64
|
||||
notificationID int64
|
||||
state api.NotifySubjectStateType
|
||||
}{
|
||||
// Issue 2 is a pull request; pull_request 1 has has_merged=true.
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
|
||||
|
||||
n := &activities_model.Notification{
|
||||
ID: 999,
|
||||
UserID: 2,
|
||||
RepoID: repo.ID,
|
||||
Status: activities_model.NotificationStatusUnread,
|
||||
Source: activities_model.NotificationSourcePullRequest,
|
||||
IssueID: issue.ID,
|
||||
Issue: issue,
|
||||
Repository: repo,
|
||||
}
|
||||
|
||||
thread := ToNotificationThread(t.Context(), n)
|
||||
require.NotNil(t, thread.Subject)
|
||||
assert.Equal(t, api.NotifySubjectPull, thread.Subject.Type)
|
||||
assert.Equal(t, api.NotifySubjectStateMerged, thread.Subject.State)
|
||||
})
|
||||
|
||||
t.Run("open pull request returns open state", func(t *testing.T) {
|
||||
{"merged pull request returns merged state", 2, 999, api.NotifySubjectStateMerged},
|
||||
// Issue 3 is a pull request; pull_request 2 has has_merged=false.
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 3})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
|
||||
{"open pull request returns open state", 3, 998, api.NotifySubjectStateOpen},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: test.issueID})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
|
||||
|
||||
n := &activities_model.Notification{
|
||||
ID: 998,
|
||||
UserID: 2,
|
||||
RepoID: repo.ID,
|
||||
Status: activities_model.NotificationStatusUnread,
|
||||
Source: activities_model.NotificationSourcePullRequest,
|
||||
IssueID: issue.ID,
|
||||
Issue: issue,
|
||||
Repository: repo,
|
||||
}
|
||||
n := &activities_model.Notification{
|
||||
ID: test.notificationID,
|
||||
UserID: 2,
|
||||
RepoID: repo.ID,
|
||||
Status: activities_model.NotificationStatusUnread,
|
||||
Source: activities_model.NotificationSourcePullRequest,
|
||||
IssueID: issue.ID,
|
||||
Issue: issue,
|
||||
Repository: repo,
|
||||
}
|
||||
|
||||
thread := ToNotificationThread(t.Context(), n)
|
||||
require.NotNil(t, thread.Subject)
|
||||
assert.Equal(t, api.NotifySubjectPull, thread.Subject.Type)
|
||||
assert.Equal(t, api.NotifySubjectStateOpen, thread.Subject.State)
|
||||
})
|
||||
thread := ToNotificationThread(t.Context(), n)
|
||||
require.NotNil(t, thread.Subject)
|
||||
assert.Equal(t, api.NotifySubjectPull, thread.Subject.Type)
|
||||
assert.Equal(t, test.state, thread.Subject.State)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func newRepoNotification(t *testing.T, repoID, userID int64) *activities_model.Notification {
|
||||
|
||||
Reference in new issue
Block a user