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
|
package cli
import (
"testing"
"codeberg.org/snonux/gitsyncer/internal/config"
)
func TestNewRepoClientForOrg(t *testing.T) {
t.Parallel()
t.Run("github", func(t *testing.T) {
client, ok := newRepoClientForOrg(config.Organization{
Host: "git@github.com",
Name: "acme",
GitHubToken: "token",
})
if !ok {
t.Fatal("expected supported github client")
}
if !client.HasToken() {
t.Fatal("expected github client token to be loaded")
}
})
t.Run("codeberg", func(t *testing.T) {
client, ok := newRepoClientForOrg(config.Organization{
Host: "git@codeberg.org",
Name: "acme",
CodebergToken: "token",
})
if !ok {
t.Fatal("expected supported codeberg client")
}
if !client.HasToken() {
t.Fatal("expected codeberg client token to be loaded")
}
})
t.Run("github host variants", func(t *testing.T) {
t.Parallel()
variantHosts := []string{
"ssh://github.com",
"git@github.company.com",
"git@github.com:acme",
"https://github.com",
}
for _, host := range variantHosts {
host := host
t.Run(host, func(t *testing.T) {
t.Parallel()
client, ok := newRepoClientForOrg(config.Organization{
Host: host,
Name: "acme",
GitHubToken: "token",
})
if !ok {
t.Fatalf("expected supported github host variant %q", host)
}
if !client.HasToken() {
t.Fatalf("expected github client token for host variant %q", host)
}
})
}
})
t.Run("codeberg host variants", func(t *testing.T) {
t.Parallel()
variantHosts := []string{
"https://codeberg.org",
"ssh://codeberg.org",
"git@codeberg.org:acme",
"git@codeberg.org.example",
}
for _, host := range variantHosts {
host := host
t.Run(host, func(t *testing.T) {
t.Parallel()
client, ok := newRepoClientForOrg(config.Organization{
Host: host,
Name: "acme",
CodebergToken: "token",
})
if !ok {
t.Fatalf("expected supported codeberg host variant %q", host)
}
if !client.HasToken() {
t.Fatalf("expected codeberg client token for host variant %q", host)
}
})
}
})
t.Run("unsupported hosts", func(t *testing.T) {
t.Parallel()
unsupportedHosts := []string{
"ssh://example.org",
"git@gitlab.com",
"file:///srv/git",
}
for _, host := range unsupportedHosts {
host := host
t.Run(host, func(t *testing.T) {
t.Parallel()
client, ok := newRepoClientForOrg(config.Organization{
Host: host,
Name: "acme",
})
if ok {
t.Fatalf("expected unsupported host %q", host)
}
if client != nil {
t.Fatalf("expected nil client for unsupported host %q", host)
}
})
}
})
}
|