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.

goget_test.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "fmt"
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/modules/setting"
  9. "code.gitea.io/gitea/tests"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestGoGet(t *testing.T) {
  13. defer tests.PrepareTestEnv(t)()
  14. req := NewRequest(t, "GET", "/blah/glah/plah?go-get=1")
  15. resp := MakeRequest(t, req, http.StatusOK)
  16. expected := fmt.Sprintf(`<!doctype html>
  17. <html>
  18. <head>
  19. <meta name="go-import" content="%[1]s:%[2]s/blah/glah git %[3]sblah/glah.git">
  20. <meta name="go-source" content="%[1]s:%[2]s/blah/glah _ %[3]sblah/glah/src/branch/master{/dir} %[3]sblah/glah/src/branch/master{/dir}/{file}#L{line}">
  21. </head>
  22. <body>
  23. go get --insecure %[1]s:%[2]s/blah/glah
  24. </body>
  25. </html>`, setting.Domain, setting.HTTPPort, setting.AppURL)
  26. assert.Equal(t, expected, resp.Body.String())
  27. }
  28. func TestGoGetForSSH(t *testing.T) {
  29. defer tests.PrepareTestEnv(t)()
  30. old := setting.Repository.GoGetCloneURLProtocol
  31. defer func() {
  32. setting.Repository.GoGetCloneURLProtocol = old
  33. }()
  34. setting.Repository.GoGetCloneURLProtocol = "ssh"
  35. req := NewRequest(t, "GET", "/blah/glah/plah?go-get=1")
  36. resp := MakeRequest(t, req, http.StatusOK)
  37. expected := fmt.Sprintf(`<!doctype html>
  38. <html>
  39. <head>
  40. <meta name="go-import" content="%[1]s:%[2]s/blah/glah git ssh://git@%[4]s:%[5]d/blah/glah.git">
  41. <meta name="go-source" content="%[1]s:%[2]s/blah/glah _ %[3]sblah/glah/src/branch/master{/dir} %[3]sblah/glah/src/branch/master{/dir}/{file}#L{line}">
  42. </head>
  43. <body>
  44. go get --insecure %[1]s:%[2]s/blah/glah
  45. </body>
  46. </html>`, setting.Domain, setting.HTTPPort, setting.AppURL, setting.SSH.Domain, setting.SSH.Port)
  47. assert.Equal(t, expected, resp.Body.String())
  48. }