You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.9 KiB
55 lines
1.9 KiB
3 years ago
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
2 years ago
|
package integration
|
||
3 years ago
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"io"
|
||
|
"net/http"
|
||
|
"net/url"
|
||
|
"testing"
|
||
|
|
||
3 years ago
|
repo_model "code.gitea.io/gitea/models/repo"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
user_model "code.gitea.io/gitea/models/user"
|
||
2 years ago
|
"code.gitea.io/gitea/tests"
|
||
3 years ago
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestAPIDownloadArchive(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
3 years ago
|
|
||
2 years ago
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||
3 years ago
|
session := loginUser(t, user2.LowerName)
|
||
|
token := getTokenForLoggedInUser(t, session)
|
||
|
|
||
|
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.zip", user2.Name, repo.Name))
|
||
|
link.RawQuery = url.Values{"token": {token}}.Encode()
|
||
|
resp := MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
||
|
bs, err := io.ReadAll(resp.Body)
|
||
|
assert.NoError(t, err)
|
||
|
assert.EqualValues(t, 320, len(bs))
|
||
|
|
||
|
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.tar.gz", user2.Name, repo.Name))
|
||
|
link.RawQuery = url.Values{"token": {token}}.Encode()
|
||
|
resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
||
|
bs, err = io.ReadAll(resp.Body)
|
||
|
assert.NoError(t, err)
|
||
|
assert.EqualValues(t, 266, len(bs))
|
||
|
|
||
|
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.bundle", user2.Name, repo.Name))
|
||
|
link.RawQuery = url.Values{"token": {token}}.Encode()
|
||
|
resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
||
|
bs, err = io.ReadAll(resp.Body)
|
||
|
assert.NoError(t, err)
|
||
|
assert.EqualValues(t, 382, len(bs))
|
||
|
|
||
|
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name))
|
||
|
link.RawQuery = url.Values{"token": {token}}.Encode()
|
||
|
MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusBadRequest)
|
||
|
}
|