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 var runtimeTarget = runtime.GOOS + "_" + runtime.GOARCH
func TestBuild(t *testing.T) { func TestDefault(t *testing.T) {
folder, back := testlib.Mktmp(t) for name, testcase := range map[string]struct {
defer back() build config.Build
writeGoodMain(t, folder) targets []string
var config = config.Project{ }{
Builds: []config.Build{ "full": {
{ build: config.Build{
Binary: "foo", Binary: "foo",
Goos: []string{ Goos: []string{
"linux", "linux",
@ -36,16 +36,57 @@ func TestBuild(t *testing.T) {
"6", "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 ctx = context.New(config)
var build = Default.Default(ctx.Config.Builds[0]) var build = ctx.Config.Builds[0]
assert.ElementsMatch(t, build.Targets, []string{
"linux_amd64",
"darwin_amd64",
"windows_amd64",
"linux_arm_6",
})
for _, target := range build.Targets { for _, target := range build.Targets {
var err = Default.Build(ctx, build, api.Options{ var err = Default.Build(ctx, build, api.Options{
Target: target, Target: target,
@ -54,7 +95,6 @@ func TestBuild(t *testing.T) {
}) })
assert.NoError(t, err) assert.NoError(t, err)
} }
assert.Len(t, ctx.Artifacts.List(), len(build.Targets)) 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) { func TestLdFlagsFullTemplate(t *testing.T) {
var config = config.Project{ var config = config.Project{
Builds: []config.Build{ Builds: []config.Build{

View File

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