code.gitea.io/gitea@v1.22.3/tests/integration/api_repo_raw_test.go (about)

     1  // Copyright 2017 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package integration
     5  
     6  import (
     7  	"net/http"
     8  	"testing"
     9  
    10  	auth_model "code.gitea.io/gitea/models/auth"
    11  	"code.gitea.io/gitea/models/unittest"
    12  	user_model "code.gitea.io/gitea/models/user"
    13  	"code.gitea.io/gitea/tests"
    14  
    15  	"github.com/stretchr/testify/assert"
    16  )
    17  
    18  func TestAPIReposRaw(t *testing.T) {
    19  	defer tests.PrepareTestEnv(t)()
    20  	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
    21  	// Login as User2.
    22  	session := loginUser(t, user.Name)
    23  	token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
    24  
    25  	for _, ref := range [...]string{
    26  		"master", // Branch
    27  		"v1.1",   // Tag
    28  		"65f1bf27bc3bf70f64657658635e66094edbcb4d", // Commit
    29  	} {
    30  		req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/raw/%s/README.md", user.Name, ref).
    31  			AddTokenAuth(token)
    32  		resp := MakeRequest(t, req, http.StatusOK)
    33  		assert.EqualValues(t, "file", resp.Header().Get("x-gitea-object-type"))
    34  	}
    35  	// Test default branch
    36  	req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/raw/README.md", user.Name).
    37  		AddTokenAuth(token)
    38  	resp := MakeRequest(t, req, http.StatusOK)
    39  	assert.EqualValues(t, "file", resp.Header().Get("x-gitea-object-type"))
    40  }