Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

internal_test.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "encoding/json"
  7. "fmt"
  8. "net/http"
  9. "net/url"
  10. "testing"
  11. "code.gitea.io/gitea/models"
  12. "code.gitea.io/gitea/modules/setting"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr, canPush bool) {
  16. reqURL := fmt.Sprintf("/api/internal/branch/%d/%s", repoID, url.QueryEscape(branchName))
  17. req := NewRequest(t, "GET", reqURL)
  18. t.Log(reqURL)
  19. req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", setting.InternalToken))
  20. resp := MakeRequest(t, req, NoExpectedStatus)
  21. if isErr {
  22. assert.EqualValues(t, http.StatusInternalServerError, resp.HeaderCode)
  23. } else {
  24. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  25. var branch models.ProtectedBranch
  26. t.Log(string(resp.Body))
  27. assert.NoError(t, json.Unmarshal(resp.Body, &branch))
  28. assert.Equal(t, canPush, branch.CanPush)
  29. }
  30. }
  31. func TestInternal_GetProtectedBranch(t *testing.T) {
  32. prepareTestEnv(t)
  33. assertProtectedBranch(t, 1, "master", false, true)
  34. assertProtectedBranch(t, 1, "dev", false, true)
  35. assertProtectedBranch(t, 1, "lunny/dev", false, true)
  36. }