1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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")))
})
}
|