@@ -3,6 +3,7 @@ package e2e
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "io/ioutil"
6
7
"math/rand"
7
8
"net"
8
9
"net/http"
@@ -28,6 +29,7 @@ type dindSwarmAndRegistryInfo struct {
28
29
registryAddress string
29
30
configuredCmd icmd.Cmd
30
31
stopRegistry func ()
32
+ registryLogs func () string
31
33
}
32
34
33
35
func runWithDindSwarmAndRegistry (t * testing.T , todo func (dindSwarmAndRegistryInfo )) {
@@ -88,6 +90,7 @@ func runWithDindSwarmAndRegistry(t *testing.T, todo func(dindSwarmAndRegistryInf
88
90
registryAddress : registry .GetAddress (t ),
89
91
swarmAddress : swarm .GetAddress (t ),
90
92
stopRegistry : registry .StopNoFail ,
93
+ registryLogs : registry .Logs (t ),
91
94
}
92
95
todo (info )
93
96
@@ -165,11 +168,16 @@ func TestPushArchs(t *testing.T) {
165
168
icmd .RunCmd (cmd ).Assert (t , icmd .Success )
166
169
167
170
var index v1.Index
168
- httpGet (t , "http://" + info .registryAddress + "/v2/test/push-pull/manifests/1" , & index )
171
+ headers := map [string ]string {
172
+ "Accept" : "application/vnd.docker.distribution.manifest.list.v2+json" ,
173
+ }
174
+ err := httpGet ("http://" + info .registryAddress + "/v2/test/push-pull/manifests/1" , headers , & index )
175
+ assert .NilError (t , err , info .registryLogs ())
169
176
digest , err := getManifestListDigest (index )
170
- assert .NilError (t , err )
177
+ assert .NilError (t , err , info . registryLogs () )
171
178
var manifestList manifestlist.ManifestList
172
- httpGet (t , "http://" + info .registryAddress + "/v2/test/push-pull/manifests/" + digest .String (), & manifestList )
179
+ err = httpGet ("http://" + info .registryAddress + "/v2/test/push-pull/manifests/" + digest .String (), headers , & manifestList )
180
+ assert .NilError (t , err )
173
181
assert .Equal (t , len (manifestList .Manifests ), len (testCase .expectedPlatforms ), "Unexpected number of platforms" )
174
182
for _ , m := range manifestList .Manifests {
175
183
assert .Assert (t , cmp .Contains (testCase .expectedPlatforms , m .Platform ), "Platform expected but not found: %s" , m .Platform )
@@ -312,13 +320,31 @@ func isPortAvailable(port int) bool {
312
320
return true
313
321
}
314
322
315
- func httpGet (t * testing.T , url string , obj interface {}) {
316
- r , err := http .Get (url )
317
- assert .NilError (t , err )
323
+ func httpGet (url string , headers map [string ]string , obj interface {}) error {
324
+ client := & http.Client {}
325
+ req , err := http .NewRequest ("GET" , url , nil )
326
+ if err != nil {
327
+ return err
328
+ }
329
+ for k , v := range headers {
330
+ req .Header .Set (k , v )
331
+ }
332
+ r , err := client .Do (req )
333
+ if err != nil {
334
+ return err
335
+ }
318
336
defer r .Body .Close ()
319
- assert .Equal (t , r .StatusCode , 200 )
320
- err = json .NewDecoder (r .Body ).Decode (obj )
321
- assert .NilError (t , err )
337
+ if r .StatusCode != http .StatusOK {
338
+ body , err := ioutil .ReadAll (r .Body )
339
+ if err != nil {
340
+ return err
341
+ }
342
+ return fmt .Errorf ("unexpected http error code %d with message %s" , r .StatusCode , string (body ))
343
+ }
344
+ if err := json .NewDecoder (r .Body ).Decode (obj ); err != nil {
345
+ return err
346
+ }
347
+ return nil
322
348
}
323
349
324
350
func getManifestListDigest (index v1.Index ) (digest.Digest , error ) {
0 commit comments