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.

internal_test.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.Code)
  23. } else {
  24. assert.EqualValues(t, http.StatusOK, resp.Code)
  25. var branch models.ProtectedBranch
  26. t.Log(resp.Body.String())
  27. assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &branch))
  28. assert.Equal(t, canPush, !branch.IsProtected())
  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. }