mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
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
This commit is contained in:
parent
f8ced34079
commit
650e14d297
@ -6,7 +6,6 @@ services:
|
|||||||
- docker
|
- docker
|
||||||
install:
|
install:
|
||||||
- make setup
|
- make setup
|
||||||
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
|
|
||||||
- gem install fpm
|
- gem install fpm
|
||||||
- sudo apt-get update
|
- sudo apt-get update
|
||||||
- sudo apt-get install --yes snapd rpm
|
- sudo apt-get install --yes snapd rpm
|
||||||
@ -17,6 +16,7 @@ script:
|
|||||||
- test -n "$TRAVIS_TAG" || go run main.go --skip-validate --skip-publish
|
- test -n "$TRAVIS_TAG" || go run main.go --skip-validate --skip-publish
|
||||||
after_success:
|
after_success:
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
|
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
|
||||||
- test -n "$TRAVIS_TAG" && go run main.go
|
- test -n "$TRAVIS_TAG" && go run main.go
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/apex/log"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/config"
|
"github.com/goreleaser/goreleaser/config"
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
"github.com/goreleaser/goreleaser/pipeline"
|
"github.com/goreleaser/goreleaser/pipeline"
|
||||||
@ -14,6 +16,23 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestRunPipe(t *testing.T) {
|
||||||
folder, err := ioutil.TempDir("", "archivetest")
|
folder, err := ioutil.TempDir("", "archivetest")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -24,8 +43,8 @@ func TestRunPipe(t *testing.T) {
|
|||||||
_, err = os.Create(binPath)
|
_, err = os.Create(binPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
var images = []string{
|
var images = []string{
|
||||||
"goreleaser/test_run_pipe:1.0.0",
|
"localhost:5000/goreleaser/test_run_pipe:1.0.0",
|
||||||
"goreleaser/test_run_pipe:latest",
|
"localhost:5000/goreleaser/test_run_pipe:latest",
|
||||||
}
|
}
|
||||||
// this might fail as the image doesnt exist yet, so lets ignore the error
|
// this might fail as the image doesnt exist yet, so lets ignore the error
|
||||||
for _, img := range images {
|
for _, img := range images {
|
||||||
@ -39,7 +58,7 @@ func TestRunPipe(t *testing.T) {
|
|||||||
Dist: dist,
|
Dist: dist,
|
||||||
Dockers: []config.Docker{
|
Dockers: []config.Docker{
|
||||||
{
|
{
|
||||||
Image: "goreleaser/test_run_pipe",
|
Image: "localhost:5000/goreleaser/test_run_pipe",
|
||||||
Goos: "linux",
|
Goos: "linux",
|
||||||
Goarch: "amd64",
|
Goarch: "amd64",
|
||||||
Dockerfile: "testdata/Dockerfile",
|
Dockerfile: "testdata/Dockerfile",
|
||||||
@ -47,7 +66,7 @@ func TestRunPipe(t *testing.T) {
|
|||||||
Latest: true,
|
Latest: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Image: "goreleaser/test_run_pipe_nope",
|
Image: "localhost:5000/goreleaser/test_run_pipe_nope",
|
||||||
Goos: "linux",
|
Goos: "linux",
|
||||||
Goarch: "amd64",
|
Goarch: "amd64",
|
||||||
Dockerfile: "testdata/Dockerfile",
|
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
|
// the test_run_pipe_nope image should not have been created, so deleting
|
||||||
// it should fail
|
// it should fail
|
||||||
assert.Error(t,
|
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(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user