|
| 1 | +// Copyright 2022 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 | + |
| 5 | +package integrations |
| 6 | + |
| 7 | +import ( |
| 8 | + "net/http" |
| 9 | + "net/url" |
| 10 | + "os" |
| 11 | + "testing" |
| 12 | + |
| 13 | + api "code.gitea.io/gitea/modules/structs" |
| 14 | + "code.gitea.io/gitea/modules/util" |
| 15 | + |
| 16 | + "github.com/stretchr/testify/assert" |
| 17 | +) |
| 18 | + |
| 19 | +func TestAPIGetRawFileOrLFS(t *testing.T) { |
| 20 | + defer prepareTestEnv(t)() |
| 21 | + |
| 22 | + // Test with raw file |
| 23 | + req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/media/README.md") |
| 24 | + resp := MakeRequest(t, req, http.StatusOK) |
| 25 | + assert.Equal(t, "# repo1\n\nDescription for repo1", resp.Body.String()) |
| 26 | + |
| 27 | + // Test with LFS |
| 28 | + onGiteaRun(t, func(t *testing.T, u *url.URL) { |
| 29 | + httpContext := NewAPITestContext(t, "user2", "repo-lfs-test") |
| 30 | + doAPICreateRepository(httpContext, false, func(t *testing.T, repository api.Repository) { |
| 31 | + u.Path = httpContext.GitPath() |
| 32 | + dstPath, err := os.MkdirTemp("", httpContext.Reponame) |
| 33 | + assert.NoError(t, err) |
| 34 | + defer util.RemoveAll(dstPath) |
| 35 | + |
| 36 | + u.Path = httpContext.GitPath() |
| 37 | + u.User = url.UserPassword("user2", userPassword) |
| 38 | + |
| 39 | + t.Run("Clone", doGitClone(dstPath, u)) |
| 40 | + |
| 41 | + dstPath2, err := os.MkdirTemp("", httpContext.Reponame) |
| 42 | + assert.NoError(t, err) |
| 43 | + defer util.RemoveAll(dstPath2) |
| 44 | + |
| 45 | + t.Run("Partial Clone", doPartialGitClone(dstPath2, u)) |
| 46 | + |
| 47 | + lfs, _ := lfsCommitAndPushTest(t, dstPath) |
| 48 | + |
| 49 | + reqLFS := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/media/"+lfs) |
| 50 | + respLFS := MakeRequestNilResponseRecorder(t, reqLFS, http.StatusOK) |
| 51 | + assert.Equal(t, littleSize, respLFS.Length) |
| 52 | + |
| 53 | + doAPIDeleteRepository(httpContext) |
| 54 | + }) |
| 55 | + }) |
| 56 | +} |
0 commit comments