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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. // Request repository commits page
  27. req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
  28. resp := session.MakeRequest(t, req, http.StatusOK)
  29. doc := NewHTMLParser(t, resp.Body)
  30. // Get first commit URL
  31. commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
  32. assert.True(t, exists)
  33. assert.NotEmpty(t, commitURL)
  34. // Call API to add status for commit
  35. req = NewRequestWithJSON(t, "POST", "/api/v1/repos/user2/repo1/statuses/"+path.Base(commitURL),
  36. api.CreateStatusOption{
  37. State: api.StatusState(state),
  38. TargetURL: "http://test.ci/",
  39. Description: "",
  40. Context: "testci",
  41. },
  42. )
  43. resp = session.MakeRequest(t, req, http.StatusCreated)
  44. req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
  45. resp = session.MakeRequest(t, req, http.StatusOK)
  46. doc = NewHTMLParser(t, resp.Body)
  47. // Check if commit status is displayed in message column
  48. sel := doc.doc.Find("#commits-table tbody tr td.message i.commit-status")
  49. assert.Equal(t, sel.Length(), 1)
  50. for _, class := range classes {
  51. assert.True(t, sel.HasClass(class))
  52. }
  53. }
  54. func TestRepoCommitsWithStatusPending(t *testing.T) {
  55. doTestRepoCommitWithStatus(t, "pending", "circle", "yellow")
  56. }
  57. func TestRepoCommitsWithStatusSuccess(t *testing.T) {
  58. doTestRepoCommitWithStatus(t, "success", "check", "green")
  59. }
  60. func TestRepoCommitsWithStatusError(t *testing.T) {
  61. doTestRepoCommitWithStatus(t, "error", "warning", "red")
  62. }
  63. func TestRepoCommitsWithStatusFailure(t *testing.T) {
  64. doTestRepoCommitWithStatus(t, "failure", "remove", "red")
  65. }
  66. func TestRepoCommitsWithStatusWarning(t *testing.T) {
  67. doTestRepoCommitWithStatus(t, "warning", "warning", "sign", "yellow")
  68. }