From cae5d07141a5d8c9f1abf5405ea570a6f235e5c6 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 13 Jul 2017 20:43:12 -0300 Subject: [PATCH] fixed tests --- context/context.go | 3 +++ context/context_test.go | 2 +- pipeline/archive/archive_test.go | 27 ++++++++++----------------- pipeline/build/build_test.go | 22 +++++++--------------- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/context/context.go b/context/context.go index 2ec451a1c..ad51a2630 100644 --- a/context/context.go +++ b/context/context.go @@ -58,6 +58,9 @@ func (ctx *Context) AddArtifact(file string) { func (ctx *Context) AddBinary(key, group, name, path string) { binariesLock.Lock() defer binariesLock.Unlock() + if ctx.Binaries == nil { + ctx.Binaries = map[string]map[string][]Binary{} + } if ctx.Binaries[key] == nil { ctx.Binaries[key] = map[string][]Binary{} } diff --git a/context/context_test.go b/context/context_test.go index a65d22ce1..de669c1cb 100644 --- a/context/context_test.go +++ b/context/context_test.go @@ -48,7 +48,7 @@ func TestMultipleBinaryAdds(t *testing.T) { f := f k := k g.Go(func() error { - ctx.AddBinary("linuxamd64", k, f) + ctx.AddBinary("linuxamd64", k, k, f) return nil }) } diff --git a/pipeline/archive/archive_test.go b/pipeline/archive/archive_test.go index c66431516..d351a88b4 100644 --- a/pipeline/archive/archive_test.go +++ b/pipeline/archive/archive_test.go @@ -6,6 +6,8 @@ import ( "path/filepath" "testing" + "fmt" + "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" "github.com/stretchr/testify/assert" @@ -36,10 +38,6 @@ func TestRunPipe(t *testing.T) { _, err = os.Create(filepath.Join(folder, "README.md")) assert.NoError(err) var ctx = &context.Context{ - Folders: map[string]string{ - "darwinamd64": "mybin_darwin_amd64", - "windowsamd64": "mybin_windows_amd64", - }, Config: config.Project{ Dist: dist, Archive: config.Archive{ @@ -55,6 +53,8 @@ func TestRunPipe(t *testing.T) { }, }, } + ctx.AddBinary("darwinamd64", "mybin_darwin_amd64", "mybin", filepath.Join(dist, "mybin_darwin_amd64", "mybin")) + ctx.AddBinary("windowsamd64", "mybin_windows_amd64", "mybin.exe", filepath.Join(dist, "mybin_windows_amd64", "mybin.exe")) for _, format := range []string{"tar.gz", "zip"} { t.Run("Archive format "+format, func(t *testing.T) { ctx.Config.Archive.Format = format @@ -84,10 +84,6 @@ func TestRunPipeBinary(t *testing.T) { _, err = os.Create(filepath.Join(folder, "README.md")) assert.NoError(err) var ctx = &context.Context{ - Folders: map[string]string{ - "darwinamd64": "mybin_darwin", - "windowsamd64": "mybin_win", - }, Config: config.Project{ Dist: dist, Builds: []config.Build{ @@ -98,7 +94,10 @@ func TestRunPipeBinary(t *testing.T) { }, }, } + ctx.AddBinary("darwinamd64", "mybin_darwin", "mybin", filepath.Join(dist, "mybin_darwin", "mybin")) + ctx.AddBinary("windowsamd64", "mybin_win", "mybin.exe", filepath.Join(dist, "mybin_win", "mybin.exe")) assert.NoError(Pipe{}.Run(ctx)) + fmt.Println(ctx.Artifacts) assert.Contains(ctx.Artifacts, "mybin_darwin/mybin") assert.Contains(ctx.Artifacts, "mybin_win/mybin.exe") assert.Len(ctx.Artifacts, 2) @@ -107,9 +106,6 @@ func TestRunPipeBinary(t *testing.T) { func TestRunPipeDistRemoved(t *testing.T) { var assert = assert.New(t) var ctx = &context.Context{ - Folders: map[string]string{ - "darwinamd64": "whatever", - }, Config: config.Project{ Dist: "/path/nope", Archive: config.Archive{ @@ -117,15 +113,13 @@ func TestRunPipeDistRemoved(t *testing.T) { }, }, } + ctx.AddBinary("windowsamd64", "nope", "no", "blah") assert.Error(Pipe{}.Run(ctx)) } func TestRunPipeInvalidGlob(t *testing.T) { var assert = assert.New(t) var ctx = &context.Context{ - Folders: map[string]string{ - "windowsamd64": "whatever", - }, Config: config.Project{ Dist: "/tmp", Archive: config.Archive{ @@ -135,6 +129,7 @@ func TestRunPipeInvalidGlob(t *testing.T) { }, }, } + ctx.AddBinary("windowsamd64", "whatever", "foo", "bar") assert.Error(Pipe{}.Run(ctx)) } @@ -151,9 +146,6 @@ func TestRunPipeGlobFailsToAdd(t *testing.T) { assert.NoError(os.MkdirAll(filepath.Join(folder, "folder", "another"), 0755)) var ctx = &context.Context{ - Folders: map[string]string{ - "windows386": "mybin", - }, Config: config.Project{ Dist: folder, Archive: config.Archive{ @@ -163,5 +155,6 @@ func TestRunPipeGlobFailsToAdd(t *testing.T) { }, }, } + ctx.AddBinary("windows386", "mybin", "mybin", "dist/mybin") assert.Error(Pipe{}.Run(ctx)) } diff --git a/pipeline/build/build_test.go b/pipeline/build/build_test.go index e995ccd90..bb5be3c09 100644 --- a/pipeline/build/build_test.go +++ b/pipeline/build/build_test.go @@ -39,8 +39,7 @@ func TestBuild(t *testing.T) { }, } var ctx = &context.Context{ - Config: config, - Binaries: map[string][]context.Binary{}, + Config: config, } assert.NoError(doBuild(ctx, ctx.Config.Builds[0], buildtarget.Runtime)) } @@ -73,8 +72,7 @@ func TestRunFullPipe(t *testing.T) { }, } var ctx = &context.Context{ - Config: config, - Binaries: map[string][]context.Binary{}, + Config: config, } assert.NoError(Pipe{}.Run(ctx)) assert.True(exists(binary), binary) @@ -107,8 +105,7 @@ func TestRunPipeFormatBinary(t *testing.T) { }, } var ctx = &context.Context{ - Config: config, - Binaries: map[string][]context.Binary{}, + Config: config, } assert.NoError(Pipe{}.Run(ctx)) assert.True(exists(binary)) @@ -140,8 +137,7 @@ func TestRunPipeArmBuilds(t *testing.T) { }, } var ctx = &context.Context{ - Config: config, - Binaries: map[string][]context.Binary{}, + Config: config, } assert.NoError(Pipe{}.Run(ctx)) assert.True(exists(binary), binary) @@ -163,8 +159,7 @@ func TestBuildFailed(t *testing.T) { }, } var ctx = &context.Context{ - Config: config, - Binaries: map[string][]context.Binary{}, + Config: config, } assert.Error(Pipe{}.Run(ctx)) } @@ -185,8 +180,7 @@ func TestRunPipeWithInvalidOS(t *testing.T) { }, } var ctx = &context.Context{ - Config: config, - Binaries: map[string][]context.Binary{}, + Config: config, } assert.NoError(Pipe{}.Run(ctx)) } @@ -222,7 +216,6 @@ func TestRunInvalidNametemplate(t *testing.T) { func TestRunInvalidLdflags(t *testing.T) { var assert = assert.New(t) var ctx = &context.Context{ - Binaries: map[string][]context.Binary{}, Config: config.Project{ Builds: []config.Build{ { @@ -258,8 +251,7 @@ func TestRunPipeFailingHooks(t *testing.T) { }, } var ctx = &context.Context{ - Config: config, - Binaries: map[string][]context.Binary{}, + Config: config, } t.Run("pre-hook", func(t *testing.T) { ctx.Config.Builds[0].Hooks.Pre = "exit 1"