Skip to content

Commit 9a39900

Browse files
committed
fix test
1 parent 838b984 commit 9a39900

File tree

2 files changed

+46
-89
lines changed

2 files changed

+46
-89
lines changed

services/asymkey/commit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func ParseCommitWithSignature(ctx context.Context, c *git.Commit) *asymkey_model
3636
}
3737

3838
// ParseCommitWithSignatureCommitter parses a commit's GPG or SSH signature.
39-
// If the commit is singed by an instance key, then committer is nil.
39+
// If the commit is singed by an instance key, then committer can be nil.
40+
// If the signature exists, even if committer is nil, the returned CommittingUser will be a non-nil fake user.
4041
func ParseCommitWithSignatureCommitter(ctx context.Context, c *git.Commit, committer *user_model.User) *asymkey_model.CommitVerification {
4142
// If no signature, just report the committer
4243
if c.Signature == nil {

tests/integration/repo_commits_test.go

Lines changed: 44 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -24,103 +24,59 @@ import (
2424

2525
func TestRepoCommits(t *testing.T) {
2626
defer tests.PrepareTestEnv(t)()
27-
28-
session := loginUser(t, "user2")
29-
30-
// Request repository commits page
31-
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
32-
resp := session.MakeRequest(t, req, http.StatusOK)
33-
34-
doc := NewHTMLParser(t, resp.Body)
35-
commitURL, exists := doc.doc.Find("#commits-table .commit-id-short").Attr("href")
36-
assert.True(t, exists)
37-
assert.NotEmpty(t, commitURL)
38-
}
39-
40-
func Test_ReposGitCommitListNotMaster(t *testing.T) {
41-
defer tests.PrepareTestEnv(t)()
42-
session := loginUser(t, "user2")
43-
req := NewRequest(t, "GET", "/user2/repo16/commits/branch/master")
44-
resp := session.MakeRequest(t, req, http.StatusOK)
45-
46-
doc := NewHTMLParser(t, resp.Body)
47-
var commits []string
48-
doc.doc.Find("#commits-table .commit-id-short").Each(func(i int, s *goquery.Selection) {
49-
commitURL, _ := s.Attr("href")
50-
commits = append(commits, path.Base(commitURL))
51-
})
52-
assert.Equal(t, []string{"69554a64c1e6030f051e5c3f94bfbd773cd6a324", "27566bd5738fc8b4e3fef3c5e72cce608537bd95", "5099b81332712fe655e34e8dd63574f503f61811"}, commits)
53-
54-
var userHrefs []string
55-
doc.doc.Find("#commits-table .author-wrapper").Each(func(i int, s *goquery.Selection) {
56-
userHref, _ := s.Attr("href")
57-
userHrefs = append(userHrefs, userHref)
58-
})
59-
assert.Equal(t, []string{"/user2", "/user21", "/user2"}, userHrefs)
60-
61-
// check last commit author wrapper
62-
req = NewRequest(t, "GET", "/user2/repo16")
63-
resp = session.MakeRequest(t, req, http.StatusOK)
64-
65-
doc = NewHTMLParser(t, resp.Body)
66-
commits = []string{}
67-
doc.doc.Find(".latest-commit .commit-id-short").Each(func(i int, s *goquery.Selection) {
68-
commitURL, _ := s.Attr("href")
69-
commits = append(commits, path.Base(commitURL))
70-
})
71-
assert.Equal(t, []string{"69554a64c1e6030f051e5c3f94bfbd773cd6a324"}, commits)
72-
73-
userHrefs = []string{}
74-
doc.doc.Find(".latest-commit .author-wrapper").Each(func(i int, s *goquery.Selection) {
75-
userHref, _ := s.Attr("href")
76-
userHrefs = append(userHrefs, userHref)
77-
})
78-
assert.Equal(t, []string{"/user2"}, userHrefs)
79-
}
80-
81-
func Test_ReposGitCommitListNoGiteaUser(t *testing.T) {
82-
// Commits list with Gitea User has been tested in Test_ReposGitCommitListNotMaster
83-
defer tests.PrepareTestEnv(t)()
8427
session := loginUser(t, "user2")
8528

86-
// check commits list for a repository with no gitea user
87-
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
88-
resp := session.MakeRequest(t, req, http.StatusOK)
89-
90-
doc := NewHTMLParser(t, resp.Body)
91-
var commits []string
92-
doc.doc.Find("#commits-table .commit-id-short").Each(func(i int, s *goquery.Selection) {
93-
commitURL, _ := s.Attr("href")
94-
commits = append(commits, path.Base(commitURL))
29+
t.Run("CommitList", func(t *testing.T) {
30+
req := NewRequest(t, "GET", "/user2/repo16/commits/branch/master")
31+
resp := session.MakeRequest(t, req, http.StatusOK)
32+
33+
var commits, userHrefs []string
34+
doc := NewHTMLParser(t, resp.Body)
35+
doc.doc.Find("#commits-table .commit-id-short").Each(func(i int, s *goquery.Selection) {
36+
commits = append(commits, path.Base(s.AttrOr("href", "")))
37+
})
38+
doc.doc.Find("#commits-table .author-wrapper").Each(func(i int, s *goquery.Selection) {
39+
userHrefs = append(userHrefs, s.AttrOr("href", ""))
40+
})
41+
assert.Equal(t, []string{"69554a64c1e6030f051e5c3f94bfbd773cd6a324", "27566bd5738fc8b4e3fef3c5e72cce608537bd95", "5099b81332712fe655e34e8dd63574f503f61811"}, commits)
42+
assert.Equal(t, []string{"/user2", "/user21", "/user2"}, userHrefs)
9543
})
96-
assert.Equal(t, []string{"65f1bf27bc3bf70f64657658635e66094edbcb4d"}, commits)
9744

98-
var gitUsers []string
99-
doc.doc.Find("#commits-table .author-wrapper").Each(func(i int, s *goquery.Selection) {
100-
assert.Equal(t, "span", goquery.NodeName(s))
101-
gitUser := s.Text()
102-
gitUsers = append(gitUsers, gitUser)
45+
t.Run("LastCommit", func(t *testing.T) {
46+
req := NewRequest(t, "GET", "/user2/repo16")
47+
resp := session.MakeRequest(t, req, http.StatusOK)
48+
doc := NewHTMLParser(t, resp.Body)
49+
commitHref := doc.doc.Find(".latest-commit .commit-id-short").AttrOr("href", "")
50+
authorHref := doc.doc.Find(".latest-commit .author-wrapper").AttrOr("href", "")
51+
assert.Equal(t, "/user2/repo16/commit/69554a64c1e6030f051e5c3f94bfbd773cd6a324", commitHref)
52+
assert.Equal(t, "/user2", authorHref)
10353
})
104-
assert.Equal(t, []string{"user1"}, gitUsers)
105-
106-
// check last commit author wrapper
107-
req = NewRequest(t, "GET", "/user2/repo1")
108-
resp = session.MakeRequest(t, req, http.StatusOK)
10954

110-
doc = NewHTMLParser(t, resp.Body)
111-
commits = []string{}
112-
doc.doc.Find(".latest-commit .commit-id-short").Each(func(i int, s *goquery.Selection) {
113-
commitURL, _ := s.Attr("href")
114-
commits = append(commits, path.Base(commitURL))
55+
t.Run("CommitListNonExistingCommiter", func(t *testing.T) {
56+
// check the commit list for a repository with no gitea user
57+
// * commit 985f0301dba5e7b34be866819cd15ad3d8f508ee (branch2)
58+
// * Author: 6543 <[email protected]>
59+
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/branch2")
60+
resp := session.MakeRequest(t, req, http.StatusOK)
61+
62+
doc := NewHTMLParser(t, resp.Body)
63+
commitHref := doc.doc.Find("#commits-table tr:first-child .commit-id-short").AttrOr("href", "")
64+
assert.Equal(t, "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee", commitHref)
65+
authorElem := doc.doc.Find("#commits-table tr:first-child .author-wrapper")
66+
assert.Equal(t, "6543", authorElem.Text())
67+
assert.Equal(t, "span", authorElem.Nodes[0].Data)
11568
})
116-
assert.Equal(t, []string{"65f1bf27bc3bf70f64657658635e66094edbcb4d"}, commits)
11769

118-
gitUsers = []string{}
119-
doc.doc.Find(".latest-commit .author-wrapper").Each(func(i int, s *goquery.Selection) {
120-
assert.Equal(t, "span", goquery.NodeName(s))
121-
gitUsers = append(gitUsers, s.Text())
70+
t.Run("LastCommitNonExistingCommiter", func(t *testing.T) {
71+
req := NewRequest(t, "GET", "/user2/repo1/src/branch/branch2")
72+
resp := session.MakeRequest(t, req, http.StatusOK)
73+
doc := NewHTMLParser(t, resp.Body)
74+
commitHref := doc.doc.Find(".latest-commit .commit-id-short").AttrOr("href", "")
75+
assert.Equal(t, "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee", commitHref)
76+
authorElem := doc.doc.Find(".latest-commit .author-wrapper")
77+
assert.Equal(t, "6543", authorElem.Text())
78+
assert.Equal(t, "span", authorElem.Nodes[0].Data)
12279
})
123-
assert.Equal(t, []string{"user1"}, gitUsers)
12480
}
12581

12682
func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {

0 commit comments

Comments
 (0)