mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
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.
46 lines
1.2 KiB
46 lines
1.2 KiB
8 years ago
|
// Copyright 2017 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.
|
||
|
|
||
|
package integrations
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"net/url"
|
||
|
"testing"
|
||
|
|
||
|
"code.gitea.io/gitea/models"
|
||
|
"code.gitea.io/gitea/modules/setting"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr, canPush bool) {
|
||
|
reqURL := fmt.Sprintf("/api/internal/branch/%d/%s", repoID, url.QueryEscape(branchName))
|
||
|
req, err := http.NewRequest("GET", reqURL, nil)
|
||
|
t.Log(reqURL)
|
||
|
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", setting.InternalToken))
|
||
|
|
||
|
assert.NoError(t, err)
|
||
|
resp := MakeRequest(req)
|
||
|
if isErr {
|
||
|
assert.EqualValues(t, 500, resp.HeaderCode)
|
||
|
} else {
|
||
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
||
|
var branch models.ProtectedBranch
|
||
|
t.Log(string(resp.Body))
|
||
|
assert.NoError(t, json.Unmarshal(resp.Body, &branch))
|
||
|
assert.Equal(t, canPush, branch.CanPush)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestInternal_GetProtectedBranch(t *testing.T) {
|
||
|
prepareTestEnv(t)
|
||
|
|
||
|
assertProtectedBranch(t, 1, "master", false, true)
|
||
|
assertProtectedBranch(t, 1, "dev", false, true)
|
||
|
assertProtectedBranch(t, 1, "lunny/dev", false, true)
|
||
|
}
|