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

git_test.go 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. "context"
  7. "fmt"
  8. "io/ioutil"
  9. "net"
  10. "net/http"
  11. "os"
  12. "path/filepath"
  13. "testing"
  14. "time"
  15. "code.gitea.io/git"
  16. "github.com/Unknwon/com"
  17. "github.com/stretchr/testify/assert"
  18. )
  19. func onGiteaWebRun(t *testing.T, callback func(*testing.T, string)) {
  20. s := http.Server{
  21. Handler: mac,
  22. }
  23. listener, err := net.Listen("tcp", "")
  24. assert.NoError(t, err)
  25. defer func() {
  26. ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
  27. s.Shutdown(ctx)
  28. cancel()
  29. }()
  30. go s.Serve(listener)
  31. _, port, err := net.SplitHostPort(listener.Addr().String())
  32. assert.NoError(t, err)
  33. callback(t, fmt.Sprintf("http://localhost:%s/", port))
  34. }
  35. func TestClone_ViaHTTP_NoLogin(t *testing.T) {
  36. prepareTestEnv(t)
  37. onGiteaWebRun(t, func(t *testing.T, urlPrefix string) {
  38. dstPath, err := ioutil.TempDir("", "repo1")
  39. assert.NoError(t, err)
  40. defer os.RemoveAll(dstPath)
  41. err = git.Clone(fmt.Sprintf("%suser2/repo1.git", urlPrefix),
  42. dstPath, git.CloneRepoOptions{})
  43. assert.NoError(t, err)
  44. assert.True(t, com.IsExist(filepath.Join(dstPath, "README.md")))
  45. })
  46. }