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.

api_branch_test.go 1.2KB

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