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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// Copyright 2022 The Gogs 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 repoutil
import (
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"gogs.io/gogs/internal/conf"
)
func TestNewCloneLink(t *testing.T) {
conf.SetMockApp(t,
conf.AppOpts{
RunUser: "git",
},
)
conf.SetMockServer(t,
conf.ServerOpts{
ExternalURL: "https://example.com/",
},
)
t.Run("regular SSH port", func(t *testing.T) {
conf.SetMockSSH(t,
conf.SSHOpts{
Domain: "example.com",
Port: 22,
},
)
got := NewCloneLink("alice", "example", false)
want := &CloneLink{
SSH: "git@example.com:alice/example.git",
HTTPS: "https://example.com/alice/example.git",
}
assert.Equal(t, want, got)
})
t.Run("irregular SSH port", func(t *testing.T) {
conf.SetMockSSH(t,
conf.SSHOpts{
Domain: "example.com",
Port: 2222,
},
)
got := NewCloneLink("alice", "example", false)
want := &CloneLink{
SSH: "ssh://git@example.com:2222/alice/example.git",
HTTPS: "https://example.com/alice/example.git",
}
assert.Equal(t, want, got)
})
t.Run("wiki", func(t *testing.T) {
conf.SetMockSSH(t,
conf.SSHOpts{
Domain: "example.com",
Port: 22,
},
)
got := NewCloneLink("alice", "example", true)
want := &CloneLink{
SSH: "git@example.com:alice/example.wiki.git",
HTTPS: "https://example.com/alice/example.wiki.git",
}
assert.Equal(t, want, got)
})
}
func TestHTMLURL(t *testing.T) {
conf.SetMockServer(t,
conf.ServerOpts{
ExternalURL: "https://example.com/",
},
)
got := HTMLURL("alice", "example")
want := "https://example.com/alice/example"
assert.Equal(t, want, got)
}
func TestCompareCommitsPath(t *testing.T) {
got := CompareCommitsPath("alice", "example", "old", "new")
want := "alice/example/compare/old...new"
assert.Equal(t, want, got)
}
func TestUserPath(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping testing on Windows")
return
}
conf.SetMockRepository(t,
conf.RepositoryOpts{
Root: "/home/git/gogs-repositories",
},
)
got := UserPath("alice")
want := "/home/git/gogs-repositories/alice"
assert.Equal(t, want, got)
}
func TestRepositoryPath(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping testing on Windows")
return
}
conf.SetMockRepository(t,
conf.RepositoryOpts{
Root: "/home/git/gogs-repositories",
},
)
got := RepositoryPath("alice", "example")
want := "/home/git/gogs-repositories/alice/example.git"
assert.Equal(t, want, got)
}
|