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.

45 lines
1.9 KiB

  1. // Copyright 2017 Gitea. 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 models
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/modules/structs"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestGetCommitStatuses(t *testing.T) {
  11. assert.NoError(t, PrepareTestDatabase())
  12. repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
  13. sha1 := "1234123412341234123412341234123412341234"
  14. statuses, maxResults, err := GetCommitStatuses(repo1, sha1, &CommitStatusOptions{})
  15. assert.NoError(t, err)
  16. assert.Equal(t, int(maxResults), 5)
  17. assert.Len(t, statuses, 5)
  18. assert.Equal(t, "ci/awesomeness", statuses[0].Context)
  19. assert.Equal(t, structs.CommitStatusPending, statuses[0].State)
  20. assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[0].APIURL())
  21. assert.Equal(t, "cov/awesomeness", statuses[1].Context)
  22. assert.Equal(t, structs.CommitStatusWarning, statuses[1].State)
  23. assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[1].APIURL())
  24. assert.Equal(t, "cov/awesomeness", statuses[2].Context)
  25. assert.Equal(t, structs.CommitStatusSuccess, statuses[2].State)
  26. assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[2].APIURL())
  27. assert.Equal(t, "ci/awesomeness", statuses[3].Context)
  28. assert.Equal(t, structs.CommitStatusFailure, statuses[3].State)
  29. assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[3].APIURL())
  30. assert.Equal(t, "deploy/awesomeness", statuses[4].Context)
  31. assert.Equal(t, structs.CommitStatusError, statuses[4].State)
  32. assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[4].APIURL())
  33. }