You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-17 01:42:37 +02:00
test: docker tests
Added tests for docker defaulter
This commit is contained in:
committed by
Carlos Alexandro Becker
parent
8535ed3811
commit
b702adfc61
@ -7,12 +7,10 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"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"
|
||||||
|
|
||||||
"github.com/apex/log"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,7 +39,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
|||||||
|
|
||||||
// Default sets the pipe defaults
|
// Default sets the pipe defaults
|
||||||
func (Pipe) Default(ctx *context.Context) error {
|
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 {
|
if len(ctx.Config.Dockers) != 1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/apex/log"
|
"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"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -131,3 +129,59 @@ func TestDockerNotInPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), ErrNoDocker.Error())
|
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)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user