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

     1  // Copyright 2022 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package integration
     5  
     6  import (
     7  	"net/http"
     8  	"net/url"
     9  	"testing"
    10  
    11  	auth_model "code.gitea.io/gitea/models/auth"
    12  	api "code.gitea.io/gitea/modules/structs"
    13  	"code.gitea.io/gitea/tests"
    14  
    15  	"github.com/stretchr/testify/assert"
    16  )
    17  
    18  func TestAPIGetRawFileOrLFS(t *testing.T) {
    19  	defer tests.PrepareTestEnv(t)()
    20  
    21  	// Test with raw file
    22  	req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/media/README.md")
    23  	resp := MakeRequest(t, req, http.StatusOK)
    24  	assert.Equal(t, "# repo1\n\nDescription for repo1", resp.Body.String())
    25  
    26  	// Test with LFS
    27  	onGiteaRun(t, func(t *testing.T, u *url.URL) {
    28  		httpContext := NewAPITestContext(t, "user2", "repo-lfs-test", auth_model.AccessTokenScopeWriteRepository)
    29  		doAPICreateRepository(httpContext, false, func(t *testing.T, repository api.Repository) {
    30  			u.Path = httpContext.GitPath()
    31  			dstPath := t.TempDir()
    32  
    33  			u.Path = httpContext.GitPath()
    34  			u.User = url.UserPassword("user2", userPassword)
    35  
    36  			t.Run("Clone", doGitClone(dstPath, u))
    37  
    38  			dstPath2 := t.TempDir()
    39  
    40  			t.Run("Partial Clone", doPartialGitClone(dstPath2, u))
    41  
    42  			lfs, _ := lfsCommitAndPushTest(t, dstPath)
    43  
    44  			reqLFS := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/media/"+lfs)
    45  			respLFS := MakeRequestNilResponseRecorder(t, reqLFS, http.StatusOK)
    46  			assert.Equal(t, littleSize, respLFS.Length)
    47  
    48  			doAPIDeleteRepository(httpContext)
    49  		})
    50  	})
    51  }