-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathregistryproxy_test.go
More file actions
133 lines (95 loc) · 4.04 KB
/
registryproxy_test.go
File metadata and controls
133 lines (95 loc) · 4.04 KB
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
128
129
130
131
132
133
package registries
import (
"testing"
)
func parseRegistryConfigsFail(t *testing.T, str string) {
_, err := parseRegistryConfigs(str)
if err == nil {
t.Fatal("Expected `parseRegistryConfigs` to fail, but it succeeded.")
}
}
func parseRegistryConfigsSuccess(t *testing.T, str string) []RegistryConfig {
val, err := parseRegistryConfigs(str)
if err != nil {
t.Fatalf("Expected `parseRegistryConfigs` to succeed, but it failed: %s", err.Error())
}
return val
}
func TestParseRegistryConfigs(t *testing.T) {
parseRegistryConfigsFail(t, "")
empty := parseRegistryConfigsSuccess(t, "[]")
if len(empty) != 0 {
t.Fatal("Expected `parseRegistryConfigs(\"[]\")` to return no configurations, but got some.")
}
single := parseRegistryConfigsSuccess(t, "[{ \"type\": \"goproxy_server\", \"url\": \"https://proxy.example.com/mod\" }]")
if len(single) != 1 {
t.Fatalf("Expected `parseRegistryConfigs` to return one configuration, but got %d.", len(single))
}
first := single[0]
if first.Type != "goproxy_server" {
t.Fatalf("Expected `Type` to be `goproxy_server`, but got `%s`", first.Type)
}
if first.URL != "https://proxy.example.com/mod" {
t.Fatalf("Expected `URL` to be `https://proxy.example.com/mod`, but got `%s`", first.URL)
}
}
func TestParseRegistryConfigsMultiple(t *testing.T) {
multiple := parseRegistryConfigsSuccess(t, "[{ \"type\": \"git_source\", \"url\": \"https://github.com/github\" }, { \"type\": \"goproxy_server\", \"url\": \"https://proxy.example.com/mod\" }]")
if len(multiple) != 2 {
t.Fatalf("Expected `parseRegistryConfigs` to return two configurations, but got %d.", len(multiple))
}
first := multiple[0]
if first.Type != "git_source" {
t.Fatalf("Expected `Type` to be `git_source`, but got `%s`", first.Type)
}
if first.URL != "https://github.com/github" {
t.Fatalf("Expected `URL` to be `https://github.com/github`, but got `%s`", first.URL)
}
second := multiple[1]
if second.Type != "goproxy_server" {
t.Fatalf("Expected `Type` to be `goproxy_server`, but got `%s`", second.Type)
}
if second.URL != "https://proxy.example.com/mod" {
t.Fatalf("Expected `URL` to be `https://proxy.example.com/mod`, but got `%s`", second.URL)
}
}
func TestParseRegistryConfigsMultipleGitSources(t *testing.T) {
multiple := parseRegistryConfigsSuccess(t, "[{ \"type\": \"git_source\", \"url\": \"https://github.com/github\" }, { \"type\": \"git_source\", \"url\": \"https://go.googlesource.com/go\" }]")
if len(multiple) != 2 {
t.Fatalf("Expected `parseRegistryConfigs` to return two configurations, but got %d.", len(multiple))
}
first := multiple[0]
if first.Type != "git_source" {
t.Fatalf("Expected `Type` to be `git_source`, but got `%s`", first.Type)
}
if first.URL != "https://github.com/github" {
t.Fatalf("Expected `URL` to be `https://github.com/github`, but got `%s`", first.URL)
}
second := multiple[1]
if second.Type != "git_source" {
t.Fatalf("Expected `Type` to be `git_source`, but got `%s`", second.Type)
}
if second.URL != "https://go.googlesource.com/go" {
t.Fatalf("Expected `URL` to be `https://go.googlesource.com/go`, but got `%s`", second.URL)
}
}
func TestParseRegistryConfigsMultipleGoProxyServers(t *testing.T) {
multiple := parseRegistryConfigsSuccess(t, "[{ \"type\": \"goproxy_server\", \"url\": \"https://proxy.example.com/mod\" }, { \"type\": \"goproxy_server\", \"url\": \"https://goproxy.io\" }]")
if len(multiple) != 2 {
t.Fatalf("Expected `parseRegistryConfigs` to return two configurations, but got %d.", len(multiple))
}
first := multiple[0]
if first.Type != "goproxy_server" {
t.Fatalf("Expected `Type` to be `goproxy_server`, but got `%s`", first.Type)
}
if first.URL != "https://proxy.example.com/mod" {
t.Fatalf("Expected `URL` to be `https://proxy.example.com/mod`, but got `%s`", first.URL)
}
second := multiple[1]
if second.Type != "goproxy_server" {
t.Fatalf("Expected `Type` to be `goproxy_server`, but got `%s`", second.Type)
}
if second.URL != "https://goproxy.io" {
t.Fatalf("Expected `URL` to be `https://goproxy.io`, but got `%s`", second.URL)
}
}