2017-03-19 01:40:26 +02:00
|
|
|
package build
|
|
|
|
|
|
|
|
import (
|
2017-03-26 02:29:38 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2017-03-26 01:24:38 +02:00
|
|
|
"runtime"
|
2017-03-19 01:40:26 +02:00
|
|
|
"testing"
|
|
|
|
|
2017-03-26 01:24:38 +02:00
|
|
|
"github.com/goreleaser/goreleaser/config"
|
|
|
|
"github.com/goreleaser/goreleaser/context"
|
2017-03-19 01:40:26 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-03-26 01:49:29 +02:00
|
|
|
func TestPipeDescription(t *testing.T) {
|
2017-03-26 01:43:42 +02:00
|
|
|
assert.NotEmpty(t, Pipe{}.Description())
|
|
|
|
}
|
|
|
|
|
2017-03-26 01:24:38 +02:00
|
|
|
func TestRun(t *testing.T) {
|
2017-04-24 19:27:21 +02:00
|
|
|
assert.NoError(t, run(runtimeTarget, []string{"go", "list", "./..."}))
|
2017-03-26 01:24:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunInvalidCommand(t *testing.T) {
|
2017-04-24 19:27:21 +02:00
|
|
|
assert.Error(t, run(runtimeTarget, []string{"gggggo", "nope"}))
|
2017-03-26 01:24:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuild(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
var config = config.Project{
|
|
|
|
Build: config.Build{
|
|
|
|
Binary: "testing",
|
|
|
|
Flags: "-n",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config,
|
|
|
|
}
|
2017-04-24 19:27:21 +02:00
|
|
|
assert.NoError(build(ctx, "build_test", runtimeTarget))
|
2017-03-19 01:40:26 +02:00
|
|
|
}
|
2017-03-26 02:29:38 +02:00
|
|
|
|
|
|
|
func TestRunFullPipe(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2017-04-15 19:18:17 +02:00
|
|
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
2017-03-26 02:29:38 +02:00
|
|
|
assert.NoError(err)
|
|
|
|
var binary = filepath.Join(folder, "testing")
|
|
|
|
var pre = filepath.Join(folder, "pre")
|
|
|
|
var post = filepath.Join(folder, "post")
|
|
|
|
var config = config.Project{
|
2017-03-26 02:31:16 +02:00
|
|
|
Dist: folder,
|
2017-03-26 02:29:38 +02:00
|
|
|
Build: config.Build{
|
|
|
|
Binary: "testing",
|
|
|
|
Flags: "-v",
|
|
|
|
Ldflags: "-X main.test=testing",
|
|
|
|
Hooks: config.Hooks{
|
|
|
|
Pre: "touch " + pre,
|
|
|
|
Post: "touch " + post,
|
|
|
|
},
|
|
|
|
Goos: []string{
|
|
|
|
runtime.GOOS,
|
|
|
|
},
|
|
|
|
Goarch: []string{
|
|
|
|
runtime.GOARCH,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config,
|
|
|
|
Archives: map[string]string{},
|
|
|
|
}
|
|
|
|
assert.NoError(Pipe{}.Run(ctx))
|
|
|
|
assert.True(exists(binary), binary)
|
|
|
|
assert.True(exists(pre), pre)
|
|
|
|
assert.True(exists(post), post)
|
|
|
|
}
|
|
|
|
|
2017-04-24 19:29:40 +02:00
|
|
|
func TestRunPipeArmBuilds(t *testing.T) {
|
2017-04-24 19:27:21 +02:00
|
|
|
assert := assert.New(t)
|
|
|
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
|
|
|
assert.NoError(err)
|
|
|
|
var binary = filepath.Join(folder, "armtesting")
|
|
|
|
var config = config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
Build: config.Build{
|
|
|
|
Binary: "armtesting",
|
|
|
|
Flags: "-v",
|
|
|
|
Ldflags: "-X main.test=armtesting",
|
|
|
|
Goos: []string{
|
|
|
|
"linux",
|
|
|
|
},
|
|
|
|
Goarch: []string{
|
|
|
|
"arm",
|
|
|
|
"arm64",
|
|
|
|
},
|
|
|
|
Goarm: []string{
|
|
|
|
"6",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config,
|
|
|
|
Archives: map[string]string{},
|
|
|
|
}
|
|
|
|
assert.NoError(Pipe{}.Run(ctx))
|
|
|
|
assert.True(exists(binary), binary)
|
|
|
|
}
|
|
|
|
|
2017-04-14 17:50:20 +02:00
|
|
|
func TestBuildFailed(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
var config = config.Project{
|
|
|
|
Build: config.Build{
|
|
|
|
Flags: "-flag-that-dont-exists-to-force-failure",
|
|
|
|
Goos: []string{
|
|
|
|
runtime.GOOS,
|
|
|
|
},
|
|
|
|
Goarch: []string{
|
|
|
|
runtime.GOARCH,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config,
|
|
|
|
Archives: map[string]string{},
|
|
|
|
}
|
|
|
|
assert.Error(Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
2017-04-14 17:38:30 +02:00
|
|
|
func TestRunPipeWithInvalidOS(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
var config = config.Project{
|
|
|
|
Build: config.Build{
|
|
|
|
Flags: "-v",
|
|
|
|
Goos: []string{
|
|
|
|
"windows",
|
|
|
|
},
|
|
|
|
Goarch: []string{
|
|
|
|
"arm",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config,
|
|
|
|
Archives: map[string]string{},
|
|
|
|
}
|
|
|
|
assert.NoError(Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
2017-04-27 01:16:52 +02:00
|
|
|
func TestRunInvalidNametemplate(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Build: config.Build{
|
|
|
|
Binary: "nametest",
|
|
|
|
Flags: "-v",
|
|
|
|
Goos: []string{
|
|
|
|
runtime.GOOS,
|
|
|
|
},
|
|
|
|
Goarch: []string{
|
|
|
|
runtime.GOARCH,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Archive: config.Archive{
|
|
|
|
NameTemplate: "{{.Binary}_{{.Os}}_{{.Arch}}_{{.Version}}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.Error(Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunInvalidLdflags(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Archives: map[string]string{},
|
|
|
|
Config: config.Project{
|
|
|
|
Build: config.Build{
|
|
|
|
Binary: "nametest",
|
|
|
|
Flags: "-v",
|
|
|
|
Ldflags: "-s -w -X main.version={{.Version}",
|
|
|
|
Goos: []string{
|
|
|
|
runtime.GOOS,
|
|
|
|
},
|
|
|
|
Goarch: []string{
|
|
|
|
runtime.GOARCH,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.Error(Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
2017-04-14 17:45:38 +02:00
|
|
|
func TestRunPipeFailingHooks(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
var config = config.Project{
|
|
|
|
Build: config.Build{
|
|
|
|
Hooks: config.Hooks{},
|
|
|
|
Goos: []string{
|
|
|
|
runtime.GOOS,
|
|
|
|
},
|
|
|
|
Goarch: []string{
|
|
|
|
runtime.GOARCH,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config,
|
|
|
|
Archives: map[string]string{},
|
|
|
|
}
|
|
|
|
t.Run("pre-hook", func(t *testing.T) {
|
|
|
|
ctx.Config.Build.Hooks.Pre = "exit 1"
|
|
|
|
assert.Error(Pipe{}.Run(ctx))
|
|
|
|
})
|
|
|
|
t.Run("post-hook", func(t *testing.T) {
|
|
|
|
ctx.Config.Build.Hooks.Post = "exit 1"
|
|
|
|
assert.Error(Pipe{}.Run(ctx))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-26 02:29:38 +02:00
|
|
|
func exists(file string) bool {
|
|
|
|
_, err := os.Stat(file)
|
|
|
|
return !os.IsNotExist(err)
|
|
|
|
}
|