1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-26 04:22:05 +02:00
goreleaser/pipeline/defaults/defaults_test.go

114 lines
2.8 KiB
Go
Raw Normal View History

2017-01-14 14:29:01 -02:00
package defaults
import (
2017-04-22 10:21:23 -03:00
"io/ioutil"
"os"
2017-01-14 14:29:01 -02:00
"testing"
2017-01-14 20:01:32 -02:00
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
2017-01-14 14:29:01 -02:00
"github.com/stretchr/testify/assert"
)
2017-03-25 20:43:42 -03:00
func TestDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.Description())
}
2017-01-14 14:29:01 -02:00
func TestFillBasicData(t *testing.T) {
2017-07-01 21:13:02 -03:00
var assert = assert.New(t)
2017-01-14 14:29:01 -02:00
var ctx = &context.Context{
2017-01-18 15:08:48 -02:00
Config: config.Project{},
2017-01-14 14:29:01 -02:00
}
assert.NoError(Pipe{}.Run(ctx))
2017-03-22 21:01:29 -03:00
assert.Equal("goreleaser", ctx.Config.Release.GitHub.Owner)
assert.Equal("goreleaser", ctx.Config.Release.GitHub.Name)
2017-07-01 21:13:02 -03:00
assert.NotEmpty(ctx.Config.Builds)
assert.Equal("goreleaser", ctx.Config.Builds[0].Binary)
assert.Equal(".", ctx.Config.Builds[0].Main)
assert.Contains(ctx.Config.Builds[0].Goos, "darwin")
assert.Contains(ctx.Config.Builds[0].Goos, "linux")
assert.Contains(ctx.Config.Builds[0].Goarch, "386")
assert.Contains(ctx.Config.Builds[0].Goarch, "amd64")
2017-01-18 15:08:48 -02:00
assert.Equal("tar.gz", ctx.Config.Archive.Format)
assert.Contains(ctx.Config.Brew.Install, "bin.install \"goreleaser\"")
2017-09-12 00:49:02 -03:00
assert.Empty(ctx.Config.Dockers)
2017-01-14 14:38:48 -02:00
assert.NotEmpty(
2017-01-18 15:08:48 -02:00
ctx.Config.Archive.NameTemplate,
2017-07-01 21:13:02 -03:00
ctx.Config.Builds[0].Ldflags,
2017-01-18 15:08:48 -02:00
ctx.Config.Archive.Files,
2017-01-14 14:38:48 -02:00
)
}
2017-05-01 09:59:18 -03:00
func TestFillPartial(t *testing.T) {
2017-07-01 21:13:02 -03:00
var assert = assert.New(t)
2017-05-01 09:59:18 -03:00
var ctx = &context.Context{
Config: config.Project{
Release: config.Release{
GitHub: config.Repo{
Owner: "goreleaser",
Name: "test",
},
},
2017-01-18 15:08:48 -02:00
Archive: config.Archive{
Files: []string{
2017-05-11 00:05:51 -03:00
"glob/*",
2017-01-18 15:08:48 -02:00
},
2017-01-14 19:52:39 -02:00
},
2017-07-01 21:13:02 -03:00
Builds: []config.Build{
{Binary: "testreleaser"},
2017-07-01 22:06:40 -03:00
{Goos: []string{"linux"}},
{
Binary: "another",
Ignore: []config.IgnoredBuild{
{Goos: "darwin", Goarch: "amd64"},
},
},
2017-07-01 21:13:02 -03:00
},
2017-09-12 00:49:02 -03:00
Dockers: []config.Docker{
{Image: "a/b"},
},
2017-01-14 14:38:48 -02:00
},
}
assert.NoError(Pipe{}.Run(ctx))
2017-01-18 15:08:48 -02:00
assert.Len(ctx.Config.Archive.Files, 1)
2017-07-01 22:06:40 -03:00
assert.Equal(`bin.install "testreleaser"`, ctx.Config.Brew.Install)
2017-09-12 00:49:02 -03:00
assert.NotEmpty(ctx.Config.Dockers[0].Binary)
assert.NotEmpty(ctx.Config.Dockers[0].Goos)
assert.NotEmpty(ctx.Config.Dockers[0].Goarch)
assert.NotEmpty(ctx.Config.Dockers[0].Dockerfile)
assert.Empty(ctx.Config.Dockers[0].Goarm)
2017-01-14 14:38:48 -02:00
}
2017-07-01 21:27:30 -03:00
func TestFillSingleBuild(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Config: config.Project{
SingleBuild: config.Build{
Main: "testreleaser",
},
},
}
assert.NoError(Pipe{}.Run(ctx))
assert.Len(ctx.Config.Builds, 1)
assert.Equal(ctx.Config.Builds[0].Binary, "goreleaser")
}
2017-04-22 10:21:23 -03:00
func TestNotAGitRepo(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err)
previous, err := os.Getwd()
assert.NoError(err)
assert.NoError(os.Chdir(folder))
defer func() {
assert.NoError(os.Chdir(previous))
}()
var ctx = &context.Context{
Config: config.Project{},
}
assert.Error(Pipe{}.Run(ctx))
}