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.1KB

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. "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. }