1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/build/build_test.go

127 lines
2.6 KiB
Go
Raw Normal View History

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"
"testing"
2017-03-26 01:24:38 +02:00
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"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) {
assert.NoError(t, run(runtime.GOOS, runtime.GOARCH, []string{"go", "list", "./..."}))
}
func TestRunInvalidCommand(t *testing.T) {
assert.Error(t, run(runtime.GOOS, runtime.GOARCH, []string{"gggggo", "nope"}))
}
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,
}
assert.NoError(build("build_test", runtime.GOOS, runtime.GOARCH, ctx))
}
2017-03-26 02:29:38 +02:00
func TestRunFullPipe(t *testing.T) {
assert := assert.New(t)
folder, err := ioutil.TempDir("", "gorelasertest")
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-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-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)
}