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_raw_test.go 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "net/http"
  6. "testing"
  7. "code.gitea.io/gitea/models/unittest"
  8. user_model "code.gitea.io/gitea/models/user"
  9. "code.gitea.io/gitea/tests"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestAPIReposRaw(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)
  18. for _, ref := range [...]string{
  19. "master", // Branch
  20. "v1.1", // Tag
  21. "65f1bf27bc3bf70f64657658635e66094edbcb4d", // Commit
  22. } {
  23. req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/raw/%s/README.md?token="+token, user.Name, ref)
  24. resp := session.MakeRequest(t, req, http.StatusOK)
  25. assert.EqualValues(t, "file", resp.Header().Get("x-gitea-object-type"))
  26. }
  27. // Test default branch
  28. req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/raw/README.md?token="+token, user.Name)
  29. resp := session.MakeRequest(t, req, http.StatusOK)
  30. assert.EqualValues(t, "file", resp.Header().Get("x-gitea-object-type"))
  31. }