diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-05-08 10:55:27 +0800 |
---|---|---|
committer | Bo-Yi Wu <appleboy.tw@gmail.com> | 2017-05-08 10:55:27 +0800 |
commit | 2bb8b3a56219f3fcba7c77c7a8fc10769b8c11bd (patch) | |
tree | 0fb4e0e204dc72f99dd3a203ee9062bee3d93392 /integrations/internal_test.go | |
parent | 79494047b062069fd8e692152d29773a22877d76 (diff) | |
download | gitea-2bb8b3a56219f3fcba7c77c7a8fc10769b8c11bd.tar.gz gitea-2bb8b3a56219f3fcba7c77c7a8fc10769b8c11bd.zip |
fix bug when push a branch name with / & fix an integration test bug (#1689)
Diffstat (limited to 'integrations/internal_test.go')
-rw-r--r-- | integrations/internal_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/integrations/internal_test.go b/integrations/internal_test.go new file mode 100644 index 0000000000..12d6fc8dc9 --- /dev/null +++ b/integrations/internal_test.go @@ -0,0 +1,45 @@ +// 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) +} |