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.

api_repo_git_ref_test.go 1.1KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2018 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. "testing"
  8. "code.gitea.io/gitea/models"
  9. )
  10. func TestAPIReposGitRefs(t *testing.T) {
  11. defer prepareTestEnv(t)()
  12. user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
  13. // Login as User2.
  14. session := loginUser(t, user.Name)
  15. token := getTokenForLoggedInUser(t, session)
  16. for _, ref := range [...]string{
  17. "refs/heads/master", // Branch
  18. "refs/tags/v1.1", // Tag
  19. } {
  20. req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/%s?token="+token, user.Name, ref)
  21. session.MakeRequest(t, req, http.StatusOK)
  22. }
  23. // Test getting all refs
  24. req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/refs?token="+token, user.Name)
  25. session.MakeRequest(t, req, http.StatusOK)
  26. // Test getting non-existent refs
  27. req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/refs/heads/unknown?token="+token, user.Name)
  28. session.MakeRequest(t, req, http.StatusNotFound)
  29. }