mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
fixed tests
This commit is contained in:
parent
dc23113c92
commit
cae5d07141
@ -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{}
|
||||
}
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user