mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
test: docker tests
Added tests for docker defaulter
This commit is contained in:
parent
8535ed3811
commit
b702adfc61
@ -7,12 +7,10 @@ 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"
|
||||
)
|
||||
|
||||
@ -41,7 +39,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
|
||||
// Default sets the pipe defaults
|
||||
func (Pipe) Default(ctx *context.Context) error {
|
||||
// TODO: this if condition looks wrong
|
||||
// only set defaults if there is exacly 1 docker setup in the config file.
|
||||
if len(ctx.Config.Dockers) != 1 {
|
||||
return nil
|
||||
}
|
||||
|
@ -8,11 +8,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/apex/log"
|
||||
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -131,3 +129,59 @@ func TestDockerNotInPath(t *testing.T) {
|
||||
}
|
||||
assert.EqualError(t, Pipe{}.Run(ctx), ErrNoDocker.Error())
|
||||
}
|
||||
|
||||
func TestDefault(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Builds: []config.Build{
|
||||
{
|
||||
Binary: "foo",
|
||||
},
|
||||
},
|
||||
Dockers: []config.Docker{
|
||||
{
|
||||
Latest: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.NoError(t, Pipe{}.Default(ctx))
|
||||
assert.Len(t, ctx.Config.Dockers, 1)
|
||||
var docker = ctx.Config.Dockers[0]
|
||||
assert.Equal(t, "linux", docker.Goos)
|
||||
assert.Equal(t, "amd64", docker.Goarch)
|
||||
assert.Equal(t, ctx.Config.Builds[0].Binary, docker.Binary)
|
||||
assert.Equal(t, "Dockerfile", docker.Dockerfile)
|
||||
}
|
||||
|
||||
func TestDefaultNoDockers(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Dockers: []config.Docker{},
|
||||
},
|
||||
}
|
||||
assert.NoError(t, Pipe{}.Default(ctx))
|
||||
assert.Empty(t, ctx.Config.Dockers)
|
||||
}
|
||||
|
||||
func TestDefaultSet(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Dockers: []config.Docker{
|
||||
{
|
||||
Goos: "windows",
|
||||
Goarch: "i386",
|
||||
Binary: "bar",
|
||||
Dockerfile: "Dockerfile.foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.NoError(t, Pipe{}.Default(ctx))
|
||||
assert.Len(t, ctx.Config.Dockers, 1)
|
||||
var docker = ctx.Config.Dockers[0]
|
||||
assert.Equal(t, "windows", docker.Goos)
|
||||
assert.Equal(t, "i386", docker.Goarch)
|
||||
assert.Equal(t, "bar", docker.Binary)
|
||||
assert.Equal(t, "Dockerfile.foo", docker.Dockerfile)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user