summaryrefslogtreecommitdiffstats
path: root/integrations/git_test.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-11-03 01:51:03 +0800
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2017-11-02 18:51:03 +0100
commitf70758dec918b01f0895bb747decfdf110ae52bd (patch)
treed15d365b386a3369944f805edfad025e7550633a /integrations/git_test.go
parenteecaba20310483f64e0e4500fa3ac85e23ced18e (diff)
downloadgitea-f70758dec918b01f0895bb747decfdf110ae52bd.tar.gz
gitea-f70758dec918b01f0895bb747decfdf110ae52bd.zip
Add git clone test on integration test (#1682)
Diffstat (limited to 'integrations/git_test.go')
-rw-r--r--integrations/git_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/integrations/git_test.go b/integrations/git_test.go
new file mode 100644
index 0000000000..5e6334d20a
--- /dev/null
+++ b/integrations/git_test.go
@@ -0,0 +1,60 @@
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package integrations
+
+import (
+ "context"
+ "fmt"
+ "io/ioutil"
+ "net"
+ "net/http"
+ "os"
+ "path/filepath"
+ "testing"
+ "time"
+
+ "code.gitea.io/git"
+
+ "github.com/Unknwon/com"
+ "github.com/stretchr/testify/assert"
+)
+
+func onGiteaWebRun(t *testing.T, callback func(*testing.T, string)) {
+ s := http.Server{
+ Handler: mac,
+ }
+
+ listener, err := net.Listen("tcp", "")
+ assert.NoError(t, err)
+
+ defer func() {
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
+ s.Shutdown(ctx)
+ cancel()
+ }()
+
+ go s.Serve(listener)
+
+ _, port, err := net.SplitHostPort(listener.Addr().String())
+ assert.NoError(t, err)
+
+ callback(t, fmt.Sprintf("http://localhost:%s/", port))
+}
+
+func TestClone_ViaHTTP_NoLogin(t *testing.T) {
+ prepareTestEnv(t)
+
+ onGiteaWebRun(t, func(t *testing.T, urlPrefix string) {
+ dstPath, err := ioutil.TempDir("", "repo1")
+ assert.NoError(t, err)
+ defer os.RemoveAll(dstPath)
+
+ err = git.Clone(fmt.Sprintf("%suser2/repo1.git", urlPrefix),
+ dstPath, git.CloneRepoOptions{})
+ assert.NoError(t, err)
+
+ assert.True(t, com.IsExist(filepath.Join(dstPath, "README.md")))
+ })
+}