1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/build/ldflags_test.go
Carlos Alexandro Becker a2eb844e44
fixed todo
2017-03-25 20:27:32 -03:00

47 lines
1.0 KiB
Go

package build
import (
"testing"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/stretchr/testify/assert"
)
func TestLdFlagsFullTemplate(t *testing.T) {
assert := assert.New(t)
var config = config.Project{
Build: config.Build{
Ldflags: "-s -w -X main.version={{.Version}} -X main.date={{.Date}} -X main.commit={{.Commit}}",
},
}
var ctx = &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.2.3",
Commit: "123",
},
Config: config,
}
flags, err := ldflags(ctx)
assert.NoError(err)
assert.Contains(flags, "-s -w")
assert.Contains(flags, "-X main.version=v1.2.3")
assert.Contains(flags, "-X main.commit=123")
assert.Contains(flags, "-X main.date=")
}
func TestInvalidTemplate(t *testing.T) {
assert := assert.New(t)
var config = config.Project{
Build: config.Build{
Ldflags: "{invalid{.Template}}}{{}}}",
},
}
var ctx = &context.Context{
Config: config,
}
flags, err := ldflags(ctx)
assert.Error(err)
assert.Equal(flags, "")
}