@@ -20,7 +20,6 @@ import (
20
20
"errors"
21
21
"fmt"
22
22
"net/http"
23
- "strings"
24
23
"testing"
25
24
26
25
"gotest.tools/v3/assert"
@@ -31,33 +30,43 @@ import (
31
30
32
31
"github.com/containerd/nerdctl/v2/pkg/testutil"
33
32
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
34
- "github.com/containerd/nerdctl/v2/pkg/testutil/testregistry "
33
+ "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/registry "
35
34
)
36
35
37
36
func TestPush (t * testing.T ) {
38
37
nerdtest .Setup ()
39
38
40
- var registryNoAuthHTTPRandom , registryNoAuthHTTPDefault , registryTokenAuthHTTPSRandom * testregistry.RegistryServer
39
+ var registryNoAuthHTTPRandom , registryNoAuthHTTPDefault , registryTokenAuthHTTPSRandom * registry.Server
40
+ var tokenServer * registry.TokenAuthServer
41
41
42
42
testCase := & test.Case {
43
- Require : require .Linux ,
43
+ Require : require .All (
44
+ require .Linux ,
45
+ nerdtest .Registry ,
46
+ ),
44
47
45
48
Setup : func (data test.Data , helpers test.Helpers ) {
46
- base := testutil .NewBase (t )
47
- registryNoAuthHTTPRandom = testregistry .NewWithNoAuth (base , 0 , false )
48
- registryNoAuthHTTPDefault = testregistry .NewWithNoAuth (base , 80 , false )
49
- registryTokenAuthHTTPSRandom = testregistry .NewWithTokenAuth (base , "admin" , "badmin" , 0 , true )
49
+ registryNoAuthHTTPRandom = nerdtest .RegistryWithNoAuth (data , helpers , 0 , false )
50
+ registryNoAuthHTTPRandom .Setup (data , helpers )
51
+ registryNoAuthHTTPDefault = nerdtest .RegistryWithNoAuth (data , helpers , 80 , false )
52
+ registryNoAuthHTTPDefault .Setup (data , helpers )
53
+ registryTokenAuthHTTPSRandom , tokenServer = nerdtest .RegistryWithTokenAuth (data , helpers , "admin" , "badmin" , 0 , true )
54
+ tokenServer .Setup (data , helpers )
55
+ registryTokenAuthHTTPSRandom .Setup (data , helpers )
50
56
},
51
57
52
58
Cleanup : func (data test.Data , helpers test.Helpers ) {
53
59
if registryNoAuthHTTPRandom != nil {
54
- registryNoAuthHTTPRandom .Cleanup (nil )
60
+ registryNoAuthHTTPRandom .Cleanup (data , helpers )
55
61
}
56
62
if registryNoAuthHTTPDefault != nil {
57
- registryNoAuthHTTPDefault .Cleanup (nil )
63
+ registryNoAuthHTTPDefault .Cleanup (data , helpers )
58
64
}
59
65
if registryTokenAuthHTTPSRandom != nil {
60
- registryTokenAuthHTTPSRandom .Cleanup (nil )
66
+ registryTokenAuthHTTPSRandom .Cleanup (data , helpers )
67
+ }
68
+ if tokenServer != nil {
69
+ tokenServer .Cleanup (data , helpers )
61
70
}
62
71
},
63
72
@@ -66,8 +75,8 @@ func TestPush(t *testing.T) {
66
75
Description : "plain http" ,
67
76
Setup : func (data test.Data , helpers test.Helpers ) {
68
77
helpers .Ensure ("pull" , "--quiet" , testutil .CommonImage )
69
- testImageRef := fmt .Sprintf ("%s:%d/%s:%s " ,
70
- registryNoAuthHTTPRandom .IP .String (), registryNoAuthHTTPRandom .Port , data .Identifier (), strings . Split ( testutil . CommonImage , ":" )[ 1 ] )
78
+ testImageRef := fmt .Sprintf ("%s:%d/%s" ,
79
+ registryNoAuthHTTPRandom .IP .String (), registryNoAuthHTTPRandom .Port , data .Identifier ())
71
80
data .Labels ().Set ("testImageRef" , testImageRef )
72
81
helpers .Ensure ("tag" , testutil .CommonImage , testImageRef )
73
82
},
@@ -86,8 +95,8 @@ func TestPush(t *testing.T) {
86
95
Require : require .Not (nerdtest .Docker ),
87
96
Setup : func (data test.Data , helpers test.Helpers ) {
88
97
helpers .Ensure ("pull" , "--quiet" , testutil .CommonImage )
89
- testImageRef := fmt .Sprintf ("%s:%d/%s:%s " ,
90
- registryNoAuthHTTPRandom .IP .String (), registryNoAuthHTTPRandom .Port , data .Identifier (), strings . Split ( testutil . CommonImage , ":" )[ 1 ] )
98
+ testImageRef := fmt .Sprintf ("%s:%d/%s" ,
99
+ registryNoAuthHTTPRandom .IP .String (), registryNoAuthHTTPRandom .Port , data .Identifier ())
91
100
data .Labels ().Set ("testImageRef" , testImageRef )
92
101
helpers .Ensure ("tag" , testutil .CommonImage , testImageRef )
93
102
},
@@ -105,8 +114,8 @@ func TestPush(t *testing.T) {
105
114
Description : "plain http with localhost" ,
106
115
Setup : func (data test.Data , helpers test.Helpers ) {
107
116
helpers .Ensure ("pull" , "--quiet" , testutil .CommonImage )
108
- testImageRef := fmt .Sprintf ("%s:%d/%s:%s " ,
109
- "127.0.0.1" , registryNoAuthHTTPRandom .Port , data .Identifier (), strings . Split ( testutil . CommonImage , ":" )[ 1 ] )
117
+ testImageRef := fmt .Sprintf ("%s:%d/%s" ,
118
+ "127.0.0.1" , registryNoAuthHTTPRandom .Port , data .Identifier ())
110
119
data .Labels ().Set ("testImageRef" , testImageRef )
111
120
helpers .Ensure ("tag" , testutil .CommonImage , testImageRef )
112
121
},
@@ -120,8 +129,8 @@ func TestPush(t *testing.T) {
120
129
Require : require .Not (nerdtest .Docker ),
121
130
Setup : func (data test.Data , helpers test.Helpers ) {
122
131
helpers .Ensure ("pull" , "--quiet" , testutil .CommonImage )
123
- testImageRef := fmt .Sprintf ("%s/%s:%s " ,
124
- registryNoAuthHTTPDefault .IP .String (), data .Identifier (), strings . Split ( testutil . CommonImage , ":" )[ 1 ] )
132
+ testImageRef := fmt .Sprintf ("%s/%s" ,
133
+ registryNoAuthHTTPDefault .IP .String (), data .Identifier ())
125
134
data .Labels ().Set ("testImageRef" , testImageRef )
126
135
helpers .Ensure ("tag" , testutil .CommonImage , testImageRef )
127
136
},
@@ -140,8 +149,8 @@ func TestPush(t *testing.T) {
140
149
Require : require .Not (nerdtest .Docker ),
141
150
Setup : func (data test.Data , helpers test.Helpers ) {
142
151
helpers .Ensure ("pull" , "--quiet" , testutil .CommonImage )
143
- testImageRef := fmt .Sprintf ("%s:%d/%s:%s " ,
144
- registryTokenAuthHTTPSRandom .IP .String (), registryTokenAuthHTTPSRandom .Port , data .Identifier (), strings . Split ( testutil . CommonImage , ":" )[ 1 ] )
152
+ testImageRef := fmt .Sprintf ("%s:%d/%s" ,
153
+ registryTokenAuthHTTPSRandom .IP .String (), registryTokenAuthHTTPSRandom .Port , data .Identifier ())
145
154
data .Labels ().Set ("testImageRef" , testImageRef )
146
155
helpers .Ensure ("tag" , testutil .CommonImage , testImageRef )
147
156
helpers .Ensure ("--insecure-registry" , "login" , "-u" , "admin" , "-p" , "badmin" ,
@@ -163,8 +172,8 @@ func TestPush(t *testing.T) {
163
172
Require : require .Not (nerdtest .Docker ),
164
173
Setup : func (data test.Data , helpers test.Helpers ) {
165
174
helpers .Ensure ("pull" , "--quiet" , testutil .CommonImage )
166
- testImageRef := fmt .Sprintf ("%s:%d/%s:%s " ,
167
- registryTokenAuthHTTPSRandom .IP .String (), registryTokenAuthHTTPSRandom .Port , data .Identifier (), strings . Split ( testutil . CommonImage , ":" )[ 1 ] )
175
+ testImageRef := fmt .Sprintf ("%s:%d/%s" ,
176
+ registryTokenAuthHTTPSRandom .IP .String (), registryTokenAuthHTTPSRandom .Port , data .Identifier ())
168
177
data .Labels ().Set ("testImageRef" , testImageRef )
169
178
helpers .Ensure ("tag" , testutil .CommonImage , testImageRef )
170
179
helpers .Ensure ("--hosts-dir" , registryTokenAuthHTTPSRandom .HostsDir , "login" , "-u" , "admin" , "-p" , "badmin" ,
@@ -186,8 +195,8 @@ func TestPush(t *testing.T) {
186
195
Require : require .Not (nerdtest .Docker ),
187
196
Setup : func (data test.Data , helpers test.Helpers ) {
188
197
helpers .Ensure ("pull" , "--quiet" , testutil .NonDistBlobImage )
189
- testImageRef := fmt .Sprintf ("%s:%d/%s:%s " ,
190
- registryNoAuthHTTPRandom .IP .String (), registryNoAuthHTTPRandom .Port , data .Identifier (), strings . Split ( testutil . NonDistBlobImage , ":" )[ 1 ] )
198
+ testImageRef := fmt .Sprintf ("%s:%d/%s" ,
199
+ registryNoAuthHTTPRandom .IP .String (), registryNoAuthHTTPRandom .Port , data .Identifier ())
191
200
data .Labels ().Set ("testImageRef" , testImageRef )
192
201
helpers .Ensure ("tag" , testutil .NonDistBlobImage , testImageRef )
193
202
},
@@ -206,7 +215,7 @@ func TestPush(t *testing.T) {
206
215
resp , err := http .Get (blobURL )
207
216
assert .Assert (t , err , "error making http request" )
208
217
if resp .Body != nil {
209
- resp .Body .Close ()
218
+ _ = resp .Body .Close ()
210
219
}
211
220
assert .Equal (t , resp .StatusCode , http .StatusNotFound , "non-distributable blob should not be available" )
212
221
},
@@ -218,8 +227,8 @@ func TestPush(t *testing.T) {
218
227
Require : require .Not (nerdtest .Docker ),
219
228
Setup : func (data test.Data , helpers test.Helpers ) {
220
229
helpers .Ensure ("pull" , "--quiet" , testutil .NonDistBlobImage )
221
- testImageRef := fmt .Sprintf ("%s:%d/%s:%s " ,
222
- registryNoAuthHTTPRandom .IP .String (), registryNoAuthHTTPRandom .Port , data .Identifier (), strings . Split ( testutil . NonDistBlobImage , ":" )[ 1 ] )
230
+ testImageRef := fmt .Sprintf ("%s:%d/%s" ,
231
+ registryNoAuthHTTPRandom .IP .String (), registryNoAuthHTTPRandom .Port , data .Identifier ())
223
232
data .Labels ().Set ("testImageRef" , testImageRef )
224
233
helpers .Ensure ("tag" , testutil .NonDistBlobImage , testImageRef )
225
234
},
@@ -238,7 +247,7 @@ func TestPush(t *testing.T) {
238
247
resp , err := http .Get (blobURL )
239
248
assert .Assert (t , err , "error making http request" )
240
249
if resp .Body != nil {
241
- resp .Body .Close ()
250
+ _ = resp .Body .Close ()
242
251
}
243
252
assert .Equal (t , resp .StatusCode , http .StatusOK , "non-distributable blob should be available" )
244
253
},
@@ -253,8 +262,8 @@ func TestPush(t *testing.T) {
253
262
),
254
263
Setup : func (data test.Data , helpers test.Helpers ) {
255
264
helpers .Ensure ("pull" , "--quiet" , testutil .UbuntuImage )
256
- testImageRef := fmt .Sprintf ("%s:%d/%s:%s " ,
257
- registryNoAuthHTTPRandom .IP .String (), registryNoAuthHTTPRandom .Port , data .Identifier (), strings . Split ( testutil . UbuntuImage , ":" )[ 1 ] )
265
+ testImageRef := fmt .Sprintf ("%s:%d/%s" ,
266
+ registryNoAuthHTTPRandom .IP .String (), registryNoAuthHTTPRandom .Port , data .Identifier ())
258
267
data .Labels ().Set ("testImageRef" , testImageRef )
259
268
helpers .Ensure ("tag" , testutil .UbuntuImage , testImageRef )
260
269
},
0 commit comments