github.com/elyscape/goreleaser@v0.66.1-0.20180515111211-5252f74ade63/internal/nametemplate/name_test.go (about)

     1  package nametemplate
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/goreleaser/goreleaser/config"
     7  	"github.com/goreleaser/goreleaser/context"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestFuncMap(t *testing.T) {
    12  	var ctx = context.New(config.Project{
    13  		ProjectName: "proj",
    14  	})
    15  	for _, tc := range []struct {
    16  		Template string
    17  		Name     string
    18  	}{
    19  		{
    20  			Template: `{{ time "2006-01-02" }}`,
    21  			Name:     "YYYY-MM-DD",
    22  		},
    23  		{
    24  			Template: `{{ time "01/02/2006" }}`,
    25  			Name:     "MM/DD/YYYY",
    26  		},
    27  		{
    28  			Template: `{{ time "01/02/2006" }}`,
    29  			Name:     "MM/DD/YYYY",
    30  		},
    31  	} {
    32  		out, err := Apply(ctx, tc.Template)
    33  		assert.NoError(t, err)
    34  		assert.NotEmpty(t, out)
    35  	}
    36  }
    37  
    38  func TestInvalidTemplate(t *testing.T) {
    39  	_, err := Apply(context.New(config.Project{}), "{{{.Foo}")
    40  	assert.EqualError(t, err, "template: release:1: unexpected \"{\" in command")
    41  }