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

repo_test.go 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. "fmt"
  7. "net/http"
  8. "testing"
  9. "code.gitea.io/gitea/modules/setting"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestViewRepo(t *testing.T) {
  13. prepareTestEnv(t)
  14. req := NewRequest(t, "GET", "/user2/repo1")
  15. MakeRequest(t, req, http.StatusOK)
  16. req = NewRequest(t, "GET", "/user3/repo3")
  17. MakeRequest(t, req, http.StatusNotFound)
  18. session := loginUser(t, "user1")
  19. session.MakeRequest(t, req, http.StatusNotFound)
  20. }
  21. func TestViewRepo2(t *testing.T) {
  22. prepareTestEnv(t)
  23. req := NewRequest(t, "GET", "/user3/repo3")
  24. session := loginUser(t, "user2")
  25. session.MakeRequest(t, req, http.StatusOK)
  26. }
  27. func TestViewRepo3(t *testing.T) {
  28. prepareTestEnv(t)
  29. req := NewRequest(t, "GET", "/user3/repo3")
  30. session := loginUser(t, "user4")
  31. session.MakeRequest(t, req, http.StatusOK)
  32. }
  33. func TestViewRepo1CloneLinkAnonymous(t *testing.T) {
  34. prepareTestEnv(t)
  35. req := NewRequest(t, "GET", "/user2/repo1")
  36. resp := MakeRequest(t, req, http.StatusOK)
  37. htmlDoc := NewHTMLParser(t, resp.Body)
  38. link, exists := htmlDoc.doc.Find("#repo-clone-https").Attr("data-link")
  39. assert.True(t, exists, "The template has changed")
  40. assert.Equal(t, setting.AppURL+"user2/repo1.git", link)
  41. _, exists = htmlDoc.doc.Find("#repo-clone-ssh").Attr("data-link")
  42. assert.False(t, exists)
  43. }
  44. func TestViewRepo1CloneLinkAuthorized(t *testing.T) {
  45. prepareTestEnv(t)
  46. session := loginUser(t, "user2")
  47. req := NewRequest(t, "GET", "/user2/repo1")
  48. resp := session.MakeRequest(t, req, http.StatusOK)
  49. htmlDoc := NewHTMLParser(t, resp.Body)
  50. link, exists := htmlDoc.doc.Find("#repo-clone-https").Attr("data-link")
  51. assert.True(t, exists, "The template has changed")
  52. assert.Equal(t, setting.AppURL+"user2/repo1.git", link)
  53. link, exists = htmlDoc.doc.Find("#repo-clone-ssh").Attr("data-link")
  54. assert.True(t, exists, "The template has changed")
  55. sshURL := fmt.Sprintf("%s@%s:user2/repo1.git", setting.RunUser, setting.SSH.Domain)
  56. assert.Equal(t, sshURL, link)
  57. }