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
|
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestGitLabServerFromFlags(t *testing.T) {
tests := []struct {
name string
gitLabServer string
gitLabAuthServer string
artifactsServer string
expected string
}{
{
name: "When gitLabServer is set",
gitLabServer: "https://gitlabserver.com",
gitLabAuthServer: "https://authserver.com",
artifactsServer: "https://artifactsserver.com",
expected: "https://gitlabserver.com",
},
{
name: "When auth server is set",
gitLabServer: "",
gitLabAuthServer: "https://authserver.com",
artifactsServer: "https://artifactsserver.com",
expected: "https://authserver.com",
},
{
name: "When only artifacts server is set",
gitLabServer: "",
gitLabAuthServer: "",
artifactsServer: "https://artifactsserver.com",
expected: "https://artifactsserver.com",
},
{
name: "When only artifacts server includes path",
gitLabServer: "",
gitLabAuthServer: "",
artifactsServer: "https://artifactsserver.com:8080/api/path",
expected: "https://artifactsserver.com:8080",
}}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
gitLabServer = &test.gitLabServer
gitLabAuthServer = &test.gitLabAuthServer
artifactsServer = &test.artifactsServer
require.Equal(t, test.expected, gitlabServerFromFlags())
})
}
}
|