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

api_branch_test.go 1.1KB

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. "net/http"
  7. "testing"
  8. api "code.gitea.io/sdk/gitea"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
  12. prepareTestEnv(t)
  13. session := loginUser(t, "user2")
  14. req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branches/%s", branchName)
  15. resp := session.MakeRequest(t, req, NoExpectedStatus)
  16. if !exists {
  17. assert.EqualValues(t, http.StatusNotFound, resp.Code)
  18. return
  19. }
  20. assert.EqualValues(t, http.StatusOK, resp.Code)
  21. var branch api.Branch
  22. DecodeJSON(t, resp, &branch)
  23. assert.EqualValues(t, branchName, branch.Name)
  24. }
  25. func TestAPIGetBranch(t *testing.T) {
  26. for _, test := range []struct {
  27. BranchName string
  28. Exists bool
  29. }{
  30. {"master", true},
  31. {"master/doesnotexist", false},
  32. {"feature/1", true},
  33. {"feature/1/doesnotexist", false},
  34. } {
  35. testAPIGetBranch(t, test.BranchName, test.Exists)
  36. }
  37. }