1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/docker/docker_test.go

118 lines
2.8 KiB
Go
Raw Normal View History

2017-09-12 05:29:12 +02:00
package docker
import (
2017-09-13 01:58:02 +02:00
"io/ioutil"
2017-09-12 05:29:12 +02:00
"os"
2017-09-13 01:58:02 +02:00
"os/exec"
"path/filepath"
2017-09-12 05:29:12 +02:00
"testing"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/pipeline"
2017-09-13 01:58:02 +02:00
"github.com/stretchr/testify/assert"
2017-09-12 05:29:12 +02:00
)
2017-09-13 01:58:02 +02:00
func TestRunPipe(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "archivetest")
assert.NoError(err)
var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755))
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var binPath = filepath.Join(dist, "mybin", "mybin")
_, err = os.Create(binPath)
assert.NoError(err)
2017-09-15 01:16:49 +02:00
var images = []string{
"goreleaser/test_run_pipe:1.0.0",
"goreleaser/test_run_pipe:latest",
}
2017-09-13 01:58:02 +02:00
// this might fail as the image doesnt exist yet, so lets ignore the error
2017-09-15 01:16:49 +02:00
for _, img := range images {
_ = exec.Command("docker", "rmi", img).Run()
}
2017-09-13 01:58:02 +02:00
var ctx = &context.Context{
2017-09-15 00:41:55 +02:00
Version: "1.0.0",
2017-09-13 01:58:02 +02:00
Publish: true,
Config: config.Project{
ProjectName: "mybin",
Dist: dist,
Dockers: []config.Docker{
{
Image: "goreleaser/test_run_pipe",
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binary: "mybin",
2017-09-15 01:16:49 +02:00
Latest: true,
2017-09-13 01:58:02 +02:00
},
{
Image: "goreleaser/test_run_pipe_nope",
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
Binary: "otherbin",
},
},
},
}
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} {
ctx.AddBinary(plat, "mybin", "mybin", binPath)
}
assert.NoError(Pipe{}.Run(ctx))
2017-09-15 01:16:49 +02:00
2017-09-13 01:58:02 +02:00
// this might should not fail as the image should have been created when
// the step ran
2017-09-15 01:16:49 +02:00
for _, img := range images {
assert.NoError(exec.Command("docker", "rmi", img).Run())
}
2017-09-13 01:58:02 +02:00
// the test_run_pipe_nope image should not have been created, so deleting
// it should fail
assert.Error(
2017-09-15 00:41:55 +02:00
exec.Command("docker", "rmi", "goreleaser/test_run_pipe_nope:1.0.0").Run(),
2017-09-13 01:58:02 +02:00
)
}
2017-09-12 05:29:12 +02:00
func TestDescription(t *testing.T) {
var assert = assert.New(t)
assert.NotEmpty(Pipe{}.Description())
}
func TestNoDockers(t *testing.T) {
var assert = assert.New(t)
assert.True(pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{}))))
}
func TestNoDockerWithoutImageName(t *testing.T) {
var assert = assert.New(t)
assert.True(pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{
Dockers: []config.Docker{
{
Goos: "linux",
},
},
}))))
}
func TestDockerNotInPath(t *testing.T) {
var assert = assert.New(t)
var path = os.Getenv("PATH")
defer func() {
assert.NoError(os.Setenv("PATH", path))
}()
assert.NoError(os.Setenv("PATH", ""))
var ctx = &context.Context{
Version: "1.0.0",
Config: config.Project{
Dockers: []config.Docker{
{
Image: "a/b",
},
},
},
}
assert.EqualError(Pipe{}.Run(ctx), ErrNoDocker.Error())
}