From 9897a001bd990a714c0c2b793af558009bb617db Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Fri, 26 Jan 2018 19:11:40 -0200 Subject: [PATCH] test: golang builder: 100% covered --- internal/builders/golang/build_test.go | 95 +++++++++++++++----------- internal/builders/golang/doc.go | 2 + 2 files changed, 57 insertions(+), 40 deletions(-) create mode 100644 internal/builders/golang/doc.go diff --git a/internal/builders/golang/build_test.go b/internal/builders/golang/build_test.go index fc6fcb819..b188b37fa 100644 --- a/internal/builders/golang/build_test.go +++ b/internal/builders/golang/build_test.go @@ -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{ diff --git a/internal/builders/golang/doc.go b/internal/builders/golang/doc.go new file mode 100644 index 000000000..336e44ac6 --- /dev/null +++ b/internal/builders/golang/doc.go @@ -0,0 +1,2 @@ +// Package golang providers a Builder implementation for golang. +package golang