1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-19 19:10:18 +02:00
goreleaser/internal/name/name_test.go

123 lines
2.8 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"
)
2017-08-27 20:45:33 -03:00
func TestChecksums(t *testing.T) {
var config = config.Project{
Checksum: config.Checksum{
NameTemplate: "{{.ProjectName }}_{{.Tag}}_{{.Version}}_checksums.txt",
},
ProjectName: "testcheck",
}
var ctx = &context.Context{
Config: config,
Version: "1.0.0",
Git: context.GitInfo{
CurrentTag: "v1.0.0",
},
}
name, err := ForChecksums(ctx)
assert.NoError(t, err)
assert.Equal(t, "testcheck_v1.0.0_1.0.0_checksums.txt", name)
2017-08-27 20:45:33 -03:00
}
2017-01-14 15:08:10 -02:00
func TestNameFor(t *testing.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", ""))
assert.NoError(t, err)
assert.Equal(t, "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) {
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", ""),
)
assert.NoError(t, err)
assert.Equal(t, "foo_Darwin_x86_64_v1.2.3_1.2.3", name)
2017-07-03 01:00:43 -03:00
}
2017-04-22 10:34:12 -03:00
func TestInvalidNameTemplate(t *testing.T) {
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", ""))
assert.Error(t, err)
2017-04-22 10:34:12 -03:00
}
2017-04-24 14:27:21 -03:00
2017-08-27 20:45:33 -03:00
func TestNameDefaultTemplate(t *testing.T) {
2017-04-24 14:27:21 -03:00
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-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)
assert.NoError(t, err)
assert.Equal(t, key, name)
2017-04-24 14:27:21 -03:00
})
}
}