1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/pipeline/build/ldflags_test.go
Carlos Alexandro Becker a9d6f0ab8c
fixed build tests
2017-07-01 13:21:07 -03:00

51 lines
1.2 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{
Builds: []config.Build{
{
Ldflags: "-s -w -X main.version={{.Version}} -X main.tag={{.Tag}} -X main.date={{.Date}} -X main.commit={{.Commit}}",
},
},
}
var ctx = &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.2.3",
Commit: "123",
},
Version: "1.2.3",
Config: config,
}
flags, err := ldflags(ctx, ctx.Config.Builds[0])
assert.NoError(err)
assert.Contains(flags, "-s -w")
assert.Contains(flags, "-X main.version=1.2.3")
assert.Contains(flags, "-X main.tag=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{
Builds: []config.Build{
{Ldflags: "{invalid{.Template}}}{{}}}"},
},
}
var ctx = &context.Context{
Config: config,
}
flags, err := ldflags(ctx, ctx.Config.Builds[0])
assert.Error(err)
assert.Equal(flags, "")
}