gitea源码

repo_archive_test.go 918B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "io"
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/modules/setting"
  9. "code.gitea.io/gitea/modules/test"
  10. "code.gitea.io/gitea/routers"
  11. "code.gitea.io/gitea/routers/web"
  12. "code.gitea.io/gitea/tests"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func TestRepoDownloadArchive(t *testing.T) {
  16. defer tests.PrepareTestEnv(t)()
  17. defer test.MockVariableValue(&setting.EnableGzip, true)()
  18. defer test.MockVariableValue(&web.GzipMinSize, 10)()
  19. defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
  20. req := NewRequest(t, "GET", "/user2/repo1/archive/master.zip")
  21. req.Header.Set("Accept-Encoding", "gzip")
  22. resp := MakeRequest(t, req, http.StatusOK)
  23. bs, err := io.ReadAll(resp.Body)
  24. assert.NoError(t, err)
  25. assert.Empty(t, resp.Header().Get("Content-Encoding"))
  26. assert.Len(t, bs, 320)
  27. }