Skip to content

Commit

Permalink
initial test
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Sep 12, 2017
1 parent 4c4b9ef commit 7e1a4b4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pipeline/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ func (Pipe) Run(ctx *context.Context) error {
if len(ctx.Config.Dockers) == 0 || ctx.Config.Dockers[0].Image == "" {
return pipeline.Skip("docker section is not configured")
}
if ctx.Config.Release.Draft {
return pipeline.Skip("release is marked as draft")
}
_, err := exec.LookPath("docker")
if err != nil {
return ErrNoDocker
Expand Down Expand Up @@ -79,6 +76,9 @@ func doRun(ctx *context.Context, folder string, docker config.Docker, binary con
if !ctx.Publish {
return pipeline.Skip("--skip-publish is set")
}
if ctx.Config.Release.Draft {
return pipeline.Skip("release is marked as draft")
}
if err := dockerPush(image); err != nil {
return err
}
Expand Down
52 changes: 52 additions & 0 deletions pipeline/docker/docker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package docker

import (
"os"
"testing"

"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/pipeline"
"github.com/tj/assert"
)

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())
}

0 comments on commit 7e1a4b4

Please sign in to comment.