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

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "net/http"
  6. "testing"
  7. auth_model "code.gitea.io/gitea/models/auth"
  8. "code.gitea.io/gitea/models/unittest"
  9. user_model "code.gitea.io/gitea/models/user"
  10. "code.gitea.io/gitea/tests"
  11. )
  12. func TestAPIReposGitRefs(t *testing.T) {
  13. defer tests.PrepareTestEnv(t)()
  14. user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
  15. // Login as User2.
  16. session := loginUser(t, user.Name)
  17. token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
  18. for _, ref := range [...]string{
  19. "refs/heads/master", // Branch
  20. "refs/tags/v1.1", // Tag
  21. } {
  22. req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/%s?token="+token, user.Name, ref)
  23. MakeRequest(t, req, http.StatusOK)
  24. }
  25. // Test getting all refs
  26. req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/refs?token="+token, user.Name)
  27. MakeRequest(t, req, http.StatusOK)
  28. // Test getting non-existent refs
  29. req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/refs/heads/unknown?token="+token, user.Name)
  30. MakeRequest(t, req, http.StatusNotFound)
  31. }