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.2KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2017 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/unittest"
  9. user_model "code.gitea.io/gitea/models/user"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestAPIReposRaw(t *testing.T) {
  13. defer prepareTestEnv(t)()
  14. user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
  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. }