Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

api_repo_file_get_test.go 1.6KB

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