From 650e14d297237e623bb4c59490fd7529c910f015 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sat, 7 Oct 2017 17:32:17 -0300 Subject: [PATCH] fix: docker tests should not depend on the main docker registry Makes it not necessary to be logged in the in the docker registry for the tests to work by using a local registry. Fixes #379 --- .travis.yml | 2 +- pipeline/docker/docker_test.go | 31 ++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 29b90ed5c..fa524f05e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ services: - docker install: - make setup - - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" - gem install fpm - sudo apt-get update - sudo apt-get install --yes snapd rpm @@ -17,6 +16,7 @@ script: - test -n "$TRAVIS_TAG" || go run main.go --skip-validate --skip-publish after_success: - bash <(curl -s https://codecov.io/bash) + - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" - test -n "$TRAVIS_TAG" && go run main.go notifications: email: false diff --git a/pipeline/docker/docker_test.go b/pipeline/docker/docker_test.go index d957df1e3..7b7237a5f 100644 --- a/pipeline/docker/docker_test.go +++ b/pipeline/docker/docker_test.go @@ -7,6 +7,8 @@ import ( "path/filepath" "testing" + "github.com/apex/log" + "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/pipeline" @@ -14,6 +16,23 @@ import ( "github.com/stretchr/testify/assert" ) +func killAndRm() { + _ = exec.Command("docker", "kill", "registry").Run() + _ = exec.Command("docker", "rm", "registry").Run() +} + +func TestMain(m *testing.M) { + killAndRm() + if err := exec.Command( + "docker", "run", "-d", "-p", "5000:5000", "--restart=always", "--name", "registry", "registry:2", + ).Run(); err != nil { + log.WithError(err).Fatal("failed to start docker registry") + } + code := m.Run() + killAndRm() + os.Exit(code) +} + func TestRunPipe(t *testing.T) { folder, err := ioutil.TempDir("", "archivetest") assert.NoError(t, err) @@ -24,8 +43,8 @@ func TestRunPipe(t *testing.T) { _, err = os.Create(binPath) assert.NoError(t, err) var images = []string{ - "goreleaser/test_run_pipe:1.0.0", - "goreleaser/test_run_pipe:latest", + "localhost:5000/goreleaser/test_run_pipe:1.0.0", + "localhost:5000/goreleaser/test_run_pipe:latest", } // this might fail as the image doesnt exist yet, so lets ignore the error for _, img := range images { @@ -39,7 +58,7 @@ func TestRunPipe(t *testing.T) { Dist: dist, Dockers: []config.Docker{ { - Image: "goreleaser/test_run_pipe", + Image: "localhost:5000/goreleaser/test_run_pipe", Goos: "linux", Goarch: "amd64", Dockerfile: "testdata/Dockerfile", @@ -47,7 +66,7 @@ func TestRunPipe(t *testing.T) { Latest: true, }, { - Image: "goreleaser/test_run_pipe_nope", + Image: "localhost:5000/goreleaser/test_run_pipe_nope", Goos: "linux", Goarch: "amd64", Dockerfile: "testdata/Dockerfile", @@ -70,7 +89,9 @@ func TestRunPipe(t *testing.T) { // the test_run_pipe_nope image should not have been created, so deleting // it should fail assert.Error(t, - exec.Command("docker", "rmi", "goreleaser/test_run_pipe_nope:1.0.0").Run(), + exec.Command( + "docker", "rmi", "localhost:5000/goreleaser/test_run_pipe_nope:1.0.0", + ).Run(), ) }