You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_commits_test.go 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "net/http"
  7. "path"
  8. "testing"
  9. api "code.gitea.io/sdk/gitea"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestRepoCommits(t *testing.T) {
  13. prepareTestEnv(t)
  14. session := loginUser(t, "user2")
  15. // Request repository commits page
  16. req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
  17. resp := session.MakeRequest(t, req, http.StatusOK)
  18. doc := NewHTMLParser(t, resp.Body)
  19. commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
  20. assert.True(t, exists)
  21. assert.NotEmpty(t, commitURL)
  22. }
  23. func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
  24. prepareTestEnv(t)
  25. session := loginUser(t, "user2")
  26. token := getTokenForLoggedInUser(t, session)
  27. // Request repository commits page
  28. req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
  29. resp := session.MakeRequest(t, req, http.StatusOK)
  30. doc := NewHTMLParser(t, resp.Body)
  31. // Get first commit URL
  32. commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
  33. assert.True(t, exists)
  34. assert.NotEmpty(t, commitURL)
  35. // Call API to add status for commit
  36. req = NewRequestWithJSON(t, "POST", "/api/v1/repos/user2/repo1/statuses/"+path.Base(commitURL)+"?token="+token,
  37. api.CreateStatusOption{
  38. State: api.StatusState(state),
  39. TargetURL: "http://test.ci/",
  40. Description: "",
  41. Context: "testci",
  42. },
  43. )
  44. resp = session.MakeRequest(t, req, http.StatusCreated)
  45. req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
  46. resp = session.MakeRequest(t, req, http.StatusOK)
  47. doc = NewHTMLParser(t, resp.Body)
  48. // Check if commit status is displayed in message column
  49. sel := doc.doc.Find("#commits-table tbody tr td.message i.commit-status")
  50. assert.Equal(t, sel.Length(), 1)
  51. for _, class := range classes {
  52. assert.True(t, sel.HasClass(class))
  53. }
  54. }
  55. func TestRepoCommitsWithStatusPending(t *testing.T) {
  56. doTestRepoCommitWithStatus(t, "pending", "circle", "yellow")
  57. }
  58. func TestRepoCommitsWithStatusSuccess(t *testing.T) {
  59. doTestRepoCommitWithStatus(t, "success", "check", "green")
  60. }
  61. func TestRepoCommitsWithStatusError(t *testing.T) {
  62. doTestRepoCommitWithStatus(t, "error", "warning", "red")
  63. }
  64. func TestRepoCommitsWithStatusFailure(t *testing.T) {
  65. doTestRepoCommitWithStatus(t, "failure", "remove", "red")
  66. }
  67. func TestRepoCommitsWithStatusWarning(t *testing.T) {
  68. doTestRepoCommitWithStatus(t, "warning", "warning", "sign", "yellow")
  69. }