1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00

test: golang builder: 100% covered

This commit is contained in:
Carlos Alexandro Becker 2018-01-26 19:11:40 -02:00
parent b297757640
commit 9897a001bd
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 57 additions and 40 deletions

View File

@ -15,13 +15,13 @@ import (
var runtimeTarget = runtime.GOOS + "_" + runtime.GOARCH
func TestBuild(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
writeGoodMain(t, folder)
var config = config.Project{
Builds: []config.Build{
{
func TestDefault(t *testing.T) {
for name, testcase := range map[string]struct {
build config.Build
targets []string
}{
"full": {
build: config.Build{
Binary: "foo",
Goos: []string{
"linux",
@ -36,16 +36,57 @@ func TestBuild(t *testing.T) {
"6",
},
},
targets: []string{
"linux_amd64",
"darwin_amd64",
"windows_amd64",
"linux_arm_6",
},
},
"empty": {
build: config.Build{
Binary: "foo",
},
targets: []string{
"linux_amd64",
"linux_386",
"darwin_amd64",
"darwin_386",
},
},
} {
t.Run(name, func(tt *testing.T) {
var config = config.Project{
Builds: []config.Build{
testcase.build,
},
}
var ctx = context.New(config)
var build = Default.Default(ctx.Config.Builds[0])
assert.ElementsMatch(t, build.Targets, testcase.targets)
})
}
}
func TestDefaultAndBuild(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
writeGoodMain(t, folder)
var config = config.Project{
Builds: []config.Build{
{
Binary: "foo",
Targets: []string{
"linux_amd64",
"darwin_amd64",
"windows_amd64",
"linux_arm_6",
},
},
},
}
var ctx = context.New(config)
var build = Default.Default(ctx.Config.Builds[0])
assert.ElementsMatch(t, build.Targets, []string{
"linux_amd64",
"darwin_amd64",
"windows_amd64",
"linux_arm_6",
})
var build = ctx.Config.Builds[0]
for _, target := range build.Targets {
var err = Default.Build(ctx, build, api.Options{
Target: target,
@ -54,7 +95,6 @@ func TestBuild(t *testing.T) {
})
assert.NoError(t, err)
}
assert.Len(t, ctx.Artifacts.List(), len(build.Targets))
}
@ -185,31 +225,6 @@ func TestRunPipeWithMainFuncNotInMainGoFile(t *testing.T) {
})
}
func TestRunPipeWithInvalidOS(t *testing.T) {
// FIXME: probably should be refactored
t.SkipNow()
folder, back := testlib.Mktmp(t)
defer back()
writeGoodMain(t, folder)
var config = config.Project{
Builds: []config.Build{
{
Lang: "go",
Flags: "-v",
Goos: []string{
"windows",
},
Goarch: []string{
"arm",
},
},
},
}
assert.NoError(t, Default.Build(context.New(config), config.Builds[0], api.Options{
Target: "windows_arm",
}))
}
func TestLdFlagsFullTemplate(t *testing.T) {
var config = config.Project{
Builds: []config.Build{

View File

@ -0,0 +1,2 @@
// Package golang providers a Builder implementation for golang.
package golang