mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
1c2afe148f
In preparation to support env vars for Docker tag_template and also to simplify the tests by not chaning the global os.Environ I've moved the parsed env var map into the context.Context.
51 lines
1.3 KiB
Go
51 lines
1.3 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) {
|
|
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}} -X "main.foo={{.Env.FOO}}"`,
|
|
},
|
|
},
|
|
}
|
|
var ctx = &context.Context{
|
|
Git: context.GitInfo{
|
|
CurrentTag: "v1.2.3",
|
|
Commit: "123",
|
|
},
|
|
Version: "1.2.3",
|
|
Config: config,
|
|
Env: map[string]string{"FOO": "123"},
|
|
}
|
|
flags, err := ldflags(ctx, ctx.Config.Builds[0])
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, flags, "-s -w")
|
|
assert.Contains(t, flags, "-X main.version=1.2.3")
|
|
assert.Contains(t, flags, "-X main.tag=v1.2.3")
|
|
assert.Contains(t, flags, "-X main.commit=123")
|
|
assert.Contains(t, flags, "-X main.date=")
|
|
assert.Contains(t, flags, `-X "main.foo=123"`)
|
|
}
|
|
|
|
func TestInvalidTemplate(t *testing.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(t, err)
|
|
assert.Equal(t, flags, "")
|
|
}
|