1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-09 13:36:56 +02:00

style: simplified template code

This commit is contained in:
Carlos Alexandro Becker 2018-04-01 15:57:25 -03:00
parent 07b2699346
commit b2dd235614
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 7 additions and 13 deletions

View File

@ -33,11 +33,8 @@ func releaseTitle(ctx *context.Context) (string, error) {
func mkFuncMap() template.FuncMap {
return template.FuncMap{
"time": func(s ...string) (string, error) {
if len(s) < 1 {
return "", nil
}
return timeNow().Format(s[0]), nil
"time": func(s string) string {
return timeNow().Format(s)
},
}
}

View File

@ -2,7 +2,6 @@ package client
import (
"testing"
"time"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
@ -10,31 +9,29 @@ import (
)
func TestFuncMap(t *testing.T) {
timeNow = func() time.Time {
return time.Date(2018, 12, 11, 10, 9, 8, 7, time.UTC)
}
var ctx = context.New(config.Project{
ProjectName: "proj",
})
for _, tc := range []struct {
Template string
Name string
Output string
}{
{
Template: `{{ time "2006-01-02" }}`,
Name: "YYYY-MM-DD",
Output: "2018-12-11",
},
{
Template: `{{ time "01/02/2006" }}`,
Name: "MM/DD/YYYY",
Output: "12/11/2018",
},
{
Template: `{{ time "01/02/2006" }}`,
Name: "MM/DD/YYYY",
},
} {
ctx.Config.Release.NameTemplate = tc.Template
out, err := releaseTitle(ctx)
assert.NoError(t, err)
assert.Equal(t, tc.Output, out)
assert.NotEmpty(t, out)
}
}