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.

pull_status_test.go 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2019 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. "fmt"
  7. "net/http"
  8. "net/url"
  9. "path"
  10. "testing"
  11. "code.gitea.io/gitea/models"
  12. api "code.gitea.io/gitea/modules/structs"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func TestPullCreate_CommitStatus(t *testing.T) {
  16. onGiteaRun(t, func(t *testing.T, u *url.URL) {
  17. session := loginUser(t, "user1")
  18. testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
  19. testEditFileToNewBranch(t, session, "user1", "repo1", "master", "status1", "README.md", "status1")
  20. url := path.Join("user1", "repo1", "compare", "master...status1")
  21. req := NewRequestWithValues(t, "POST", url,
  22. map[string]string{
  23. "_csrf": GetCSRF(t, session, url),
  24. "title": "pull request from status1",
  25. },
  26. )
  27. session.MakeRequest(t, req, http.StatusFound)
  28. req = NewRequest(t, "GET", "/user1/repo1/pulls")
  29. resp := session.MakeRequest(t, req, http.StatusOK)
  30. doc := NewHTMLParser(t, resp.Body)
  31. // Request repository commits page
  32. req = NewRequest(t, "GET", "/user1/repo1/pulls/1/commits")
  33. resp = session.MakeRequest(t, req, http.StatusOK)
  34. doc = NewHTMLParser(t, resp.Body)
  35. // Get first commit URL
  36. commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Last().Attr("href")
  37. assert.True(t, exists)
  38. assert.NotEmpty(t, commitURL)
  39. commitID := path.Base(commitURL)
  40. statusList := []models.CommitStatusState{
  41. models.CommitStatusPending,
  42. models.CommitStatusError,
  43. models.CommitStatusFailure,
  44. models.CommitStatusWarning,
  45. models.CommitStatusSuccess,
  46. }
  47. statesIcons := map[models.CommitStatusState]string{
  48. models.CommitStatusPending: "circle icon yellow",
  49. models.CommitStatusSuccess: "check icon green",
  50. models.CommitStatusError: "warning icon red",
  51. models.CommitStatusFailure: "remove icon red",
  52. models.CommitStatusWarning: "warning sign icon yellow",
  53. }
  54. // Update commit status, and check if icon is updated as well
  55. for _, status := range statusList {
  56. // Call API to add status for commit
  57. token := getTokenForLoggedInUser(t, session)
  58. req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/user1/repo1/statuses/%s?token=%s", commitID, token),
  59. api.CreateStatusOption{
  60. State: api.StatusState(status),
  61. TargetURL: "http://test.ci/",
  62. Description: "",
  63. Context: "testci",
  64. },
  65. )
  66. session.MakeRequest(t, req, http.StatusCreated)
  67. req = NewRequestf(t, "GET", "/user1/repo1/pulls/1/commits")
  68. resp = session.MakeRequest(t, req, http.StatusOK)
  69. doc = NewHTMLParser(t, resp.Body)
  70. commitURL, exists = doc.doc.Find("#commits-table tbody tr td.sha a").Last().Attr("href")
  71. assert.True(t, exists)
  72. assert.NotEmpty(t, commitURL)
  73. assert.EqualValues(t, commitID, path.Base(commitURL))
  74. cls, ok := doc.doc.Find("#commits-table tbody tr td.message i.commit-status").Last().Attr("class")
  75. assert.True(t, ok)
  76. assert.EqualValues(t, "commit-status "+statesIcons[status], cls)
  77. }
  78. })
  79. }