1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-28 04:44:34 +02:00
goreleaser/internal/name/name_test.go

113 lines
2.5 KiB
Go
Raw Normal View History

2017-07-01 12:14:43 -03:00
package name
2017-01-14 15:08:10 -02:00
import (
"testing"
2017-01-14 20:01:32 -02:00
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
2017-07-06 19:49:21 -03:00
"github.com/goreleaser/goreleaser/internal/buildtarget"
2017-04-24 14:27:21 -03:00
"github.com/goreleaser/goreleaser/pipeline/defaults"
2017-01-14 15:08:10 -02:00
"github.com/stretchr/testify/assert"
)
func TestNameFor(t *testing.T) {
assert := assert.New(t)
2017-01-18 15:08:48 -02:00
var config = config.Project{
2017-01-15 14:53:24 -02:00
Archive: config.Archive{
NameTemplate: "{{.Binary}}_{{.Os}}_{{.Arch}}_{{.Tag}}_{{.Version}}",
2017-01-14 15:08:10 -02:00
Replacements: map[string]string{
"darwin": "Darwin",
"amd64": "x86_64",
},
},
2017-07-01 22:42:10 -03:00
ProjectName: "test",
2017-01-14 15:08:10 -02:00
}
var ctx = &context.Context{
Config: config,
Version: "1.2.3",
2017-01-18 15:08:48 -02:00
Git: context.GitInfo{
2017-01-14 15:08:10 -02:00
CurrentTag: "v1.2.3",
},
}
2017-07-06 19:49:21 -03:00
name, err := For(ctx, buildtarget.New("darwin", "amd64", ""))
2017-01-14 15:08:10 -02:00
assert.NoError(err)
assert.Equal("test_Darwin_x86_64_v1.2.3_1.2.3", name)
2017-01-14 15:08:10 -02:00
}
2017-04-22 10:34:12 -03:00
2017-07-03 01:00:43 -03:00
func TestNameForBuild(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{
Config: config.Project{
Archive: config.Archive{
NameTemplate: "{{.Binary}}_{{.Os}}_{{.Arch}}_{{.Tag}}_{{.Version}}",
Replacements: map[string]string{
"darwin": "Darwin",
"amd64": "x86_64",
},
},
ProjectName: "test",
},
Version: "1.2.3",
Git: context.GitInfo{
CurrentTag: "v1.2.3",
},
}
2017-07-06 19:49:21 -03:00
name, err := ForBuild(
ctx,
config.Build{Binary: "foo"},
buildtarget.New("darwin", "amd64", ""),
)
2017-07-03 01:00:43 -03:00
assert.NoError(err)
assert.Equal("foo_Darwin_x86_64_v1.2.3_1.2.3", name)
}
2017-04-22 10:34:12 -03:00
func TestInvalidNameTemplate(t *testing.T) {
2017-07-01 12:14:43 -03:00
var assert = assert.New(t)
2017-04-22 10:34:12 -03:00
var ctx = &context.Context{
2017-07-01 12:14:43 -03:00
Config: config.Project{
Archive: config.Archive{
NameTemplate: "{{.Binary}_{{.Os}}_{{.Arch}}_{{.Version}}",
},
2017-07-01 22:42:10 -03:00
ProjectName: "test",
2017-07-01 12:14:43 -03:00
},
2017-04-22 10:34:12 -03:00
Git: context.GitInfo{
CurrentTag: "v1.2.3",
},
}
2017-07-06 19:49:21 -03:00
_, err := For(ctx, buildtarget.New("darwin", "amd64", ""))
2017-04-22 10:34:12 -03:00
assert.Error(err)
}
2017-04-24 14:27:21 -03:00
func TestNameDefaltTemplate(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{
Config: config.Project{
Archive: config.Archive{
NameTemplate: defaults.NameTemplate,
},
2017-07-01 22:42:10 -03:00
ProjectName: "test",
2017-04-24 14:27:21 -03:00
},
Version: "1.2.3",
}
2017-07-01 12:14:43 -03:00
type buildTarget struct {
goos, goarch, goarm string
}
2017-07-06 19:49:21 -03:00
for key, target := range map[string]buildtarget.Target{
"test_1.2.3_darwin_amd64": buildtarget.New("darwin", "amd64", ""),
"test_1.2.3_linux_arm64": buildtarget.New("linux", "arm64", ""),
"test_1.2.3_linux_armv7": buildtarget.New("linux", "arm", "7"),
2017-04-24 14:27:21 -03:00
} {
t.Run(key, func(t *testing.T) {
2017-07-06 19:49:21 -03:00
name, err := For(ctx, target)
2017-04-24 14:27:21 -03:00
assert.NoError(err)
assert.Equal(key, name)
})
}
}