Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 8d52f6d

Browse files
authored
Merge pull request #581 from jcsirot/fix-e2e-tests-mac-ci
Investigate CI e2e tests failures on mac
2 parents 8827b0d + 09640b8 commit 8d52f6d

File tree

4 files changed

+57
-10
lines changed

4 files changed

+57
-10
lines changed

BUILDING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,13 @@ you forgot to rebuild the base invocation image, simply run
111111
```sh
112112
$ make -f docker.Makefile invocation-image
113113
```
114+
115+
### Running specific end-to-end tests
116+
117+
To execute a specific end-to-end test or set of end-to-end tests you can specify
118+
them with the E2E_TESTS Makefile variable.
119+
120+
```console
121+
# run the e2e test <TEST_NAME>:
122+
make E2E_TESTS=<TEST_NAME> test-e2e
123+
```

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ ifeq ($(OS),Windows_NT)
2424
EXEC_EXT := .exe
2525
endif
2626

27+
INCLUDE_E2E :=
28+
ifneq ($(E2E_TESTS),)
29+
INCLUDE_E2E := -run $(E2E_TESTS)
30+
endif
31+
2732
TEST_RESULTS_DIR = _build/test-results
2833
STATIC_FLAGS= CGO_ENABLED=0
2934
GO_BUILD = $(STATIC_FLAGS) go build -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS)
@@ -78,7 +83,7 @@ lint: ## run linter(s)
7883
test-e2e: bin/$(BIN_NAME) ## run end-to-end tests
7984
@echo "Running e2e tests..."
8085
@$(call mkdir,$(TEST_RESULTS_DIR))
81-
$(call GO_TESTSUM,e2e.xml) -v ./e2e/
86+
$(call GO_TESTSUM,e2e.xml) -v ./e2e/ $(INCLUDE_E2E)
8287

8388
test-unit: ## run unit tests
8489
@echo "Running unit tests..."

e2e/helper_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,9 @@ func (c *Container) GetPrivateAddress(t *testing.T) string {
107107
result := icmd.RunCommand(dockerCli.path, "inspect", container, "-f", "{{.NetworkSettings.IPAddress}}").Assert(t, icmd.Success)
108108
return fmt.Sprintf("%s:%d", strings.TrimSpace(result.Stdout()), c.privatePort)
109109
}
110+
111+
func (c *Container) Logs(t *testing.T) func() string {
112+
return func() string {
113+
return icmd.RunCommand(dockerCli.path, "logs", c.container).Assert(t, icmd.Success).Combined()
114+
}
115+
}

e2e/pushpull_test.go

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package e2e
33
import (
44
"encoding/json"
55
"fmt"
6+
"io/ioutil"
67
"math/rand"
78
"net"
89
"net/http"
@@ -28,6 +29,7 @@ type dindSwarmAndRegistryInfo struct {
2829
registryAddress string
2930
configuredCmd icmd.Cmd
3031
stopRegistry func()
32+
registryLogs func() string
3133
}
3234

3335
func runWithDindSwarmAndRegistry(t *testing.T, todo func(dindSwarmAndRegistryInfo)) {
@@ -88,6 +90,7 @@ func runWithDindSwarmAndRegistry(t *testing.T, todo func(dindSwarmAndRegistryInf
8890
registryAddress: registry.GetAddress(t),
8991
swarmAddress: swarm.GetAddress(t),
9092
stopRegistry: registry.StopNoFail,
93+
registryLogs: registry.Logs(t),
9194
}
9295
todo(info)
9396

@@ -165,11 +168,16 @@ func TestPushArchs(t *testing.T) {
165168
icmd.RunCmd(cmd).Assert(t, icmd.Success)
166169

167170
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())
169176
digest, err := getManifestListDigest(index)
170-
assert.NilError(t, err)
177+
assert.NilError(t, err, info.registryLogs())
171178
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)
173181
assert.Equal(t, len(manifestList.Manifests), len(testCase.expectedPlatforms), "Unexpected number of platforms")
174182
for _, m := range manifestList.Manifests {
175183
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 {
312320
return true
313321
}
314322

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+
}
318336
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
322348
}
323349

324350
func getManifestListDigest(index v1.Index) (digest.Digest, error) {

0 commit comments

Comments
 (0)