added some docker pipe tests

This commit is contained in:
Carlos Alexandro Becker
2017-09-12 20:58:02 -03:00
parent 9f95e2a3c8
commit bbc594864e
3 changed files with 64 additions and 2 deletions
+3 -1
View File
@@ -7,10 +7,12 @@ import (
"os/exec"
"path/filepath"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/pipeline"
"github.com/apex/log"
"github.com/pkg/errors"
)
+59 -1
View File
@@ -1,15 +1,73 @@
package docker
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/pipeline"
"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)
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)
// this might fail as the image doesnt exist yet, so lets ignore the error
_ = exec.Command("docker", "rmi", "goreleaser/test_run_pipe:v1.0.0").Run()
var ctx = &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.0",
},
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",
},
{
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))
// this might should not fail as the image should have been created when
// the step ran
assert.NoError(
exec.Command("docker", "rmi", "goreleaser/test_run_pipe:v1.0.0").Run(),
)
// the test_run_pipe_nope image should not have been created, so deleting
// it should fail
assert.Error(
exec.Command("docker", "rmi", "goreleaser/test_run_pipe_nope:v1.0.0").Run(),
)
}
func TestDescription(t *testing.T) {
var assert = assert.New(t)
assert.NotEmpty(Pipe{}.Description())
+2
View File
@@ -0,0 +1,2 @@
FROM scratch
ADD mybin /