-
Notifications
You must be signed in to change notification settings - Fork 82
/
regclient_test.go
103 lines (99 loc) · 2.05 KB
/
regclient_test.go
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
package regclient
import (
"testing"
"github.com/sirupsen/logrus"
"github.com/regclient/regclient/scheme/reg"
)
func TestNew(t *testing.T) {
t.Parallel()
logPtr := logrus.New()
tt := []struct {
name string
opts []Opt
expect RegClient
}{
{
name: "default",
opts: []Opt{},
expect: RegClient{},
},
{
name: "regOpt",
opts: []Opt{
WithRegOpts(
reg.WithBlobLimit(1234),
reg.WithBlobSize(64, 128),
),
},
expect: RegClient{
regOpts: []reg.Opts{
reg.WithBlobLimit(1234),
reg.WithBlobSize(64, 128),
},
},
},
{
name: "regOpt separate",
opts: []Opt{
WithRegOpts(reg.WithBlobLimit(1234)),
WithRegOpts(reg.WithBlobSize(64, 128)),
},
expect: RegClient{
regOpts: []reg.Opts{
reg.WithBlobLimit(1234),
reg.WithBlobSize(64, 128),
},
},
},
{
name: "log",
opts: []Opt{
WithLog(logPtr),
},
expect: RegClient{
log: logPtr,
},
},
{
name: "userAgent",
opts: []Opt{
WithUserAgent("unit-test"),
},
expect: RegClient{
userAgent: "unit-test",
},
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
result := New(tc.opts...)
if tc.expect.hosts != nil {
if result.hosts == nil {
t.Errorf("host is nil")
} else {
for name := range tc.expect.hosts {
if _, ok := result.hosts[name]; !ok {
t.Errorf("host entry missing for %s", name)
}
}
}
}
if tc.expect.log != nil {
if result.log == nil {
t.Errorf("log is nil")
} else if result.log != tc.expect.log {
t.Errorf("log pointer mismatch")
}
}
if len(tc.expect.regOpts) > 0 {
if len(tc.expect.regOpts)+3 != len(result.regOpts) {
t.Errorf("regOpts length mismatch, expected %d, received %d", len(tc.expect.regOpts), len(result.regOpts))
}
// TODO: can content of each regOpt be compared?
}
if tc.expect.userAgent != "" && tc.expect.userAgent != result.userAgent {
t.Errorf("userAgent, expected %s, received %s", tc.expect.userAgent, result.userAgent)
}
})
}
}