code.gitea.io/gitea@v1.21.7/tests/integration/api_repo_archive_test.go (about) 1 // Copyright 2021 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package integration 5 6 import ( 7 "fmt" 8 "io" 9 "net/http" 10 "net/url" 11 "testing" 12 13 auth_model "code.gitea.io/gitea/models/auth" 14 repo_model "code.gitea.io/gitea/models/repo" 15 "code.gitea.io/gitea/models/unittest" 16 user_model "code.gitea.io/gitea/models/user" 17 "code.gitea.io/gitea/tests" 18 19 "github.com/stretchr/testify/assert" 20 ) 21 22 func TestAPIDownloadArchive(t *testing.T) { 23 defer tests.PrepareTestEnv(t)() 24 25 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) 26 user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 27 session := loginUser(t, user2.LowerName) 28 token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) 29 30 link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.zip", user2.Name, repo.Name)) 31 link.RawQuery = url.Values{"token": {token}}.Encode() 32 resp := MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) 33 bs, err := io.ReadAll(resp.Body) 34 assert.NoError(t, err) 35 assert.Len(t, bs, 320) 36 37 link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.tar.gz", user2.Name, repo.Name)) 38 link.RawQuery = url.Values{"token": {token}}.Encode() 39 resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) 40 bs, err = io.ReadAll(resp.Body) 41 assert.NoError(t, err) 42 assert.Len(t, bs, 266) 43 44 link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.bundle", user2.Name, repo.Name)) 45 link.RawQuery = url.Values{"token": {token}}.Encode() 46 resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) 47 bs, err = io.ReadAll(resp.Body) 48 assert.NoError(t, err) 49 assert.Len(t, bs, 382) 50 51 link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name)) 52 link.RawQuery = url.Values{"token": {token}}.Encode() 53 MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusBadRequest) 54 }