github.com/triarius/goreleaser@v1.12.5/internal/pipe/release/body_test.go (about) 1 package release 2 3 import ( 4 "testing" 5 6 "github.com/triarius/goreleaser/internal/golden" 7 "github.com/triarius/goreleaser/pkg/config" 8 "github.com/triarius/goreleaser/pkg/context" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestDescribeBody(t *testing.T) { 13 changelog := "feature1: description\nfeature2: other description" 14 ctx := context.New(config.Project{}) 15 ctx.ReleaseNotes = changelog 16 out, err := describeBody(ctx) 17 require.NoError(t, err) 18 19 golden.RequireEqual(t, out.Bytes()) 20 } 21 22 func TestDontEscapeHTML(t *testing.T) { 23 changelog := "<h1>test</h1>" 24 ctx := context.New(config.Project{}) 25 ctx.ReleaseNotes = changelog 26 27 out, err := describeBody(ctx) 28 require.NoError(t, err) 29 require.Contains(t, out.String(), changelog) 30 } 31 32 func TestDescribeBodyWithHeaderAndFooter(t *testing.T) { 33 changelog := "feature1: description\nfeature2: other description" 34 ctx := context.New(config.Project{ 35 Release: config.Release{ 36 Header: "## Yada yada yada\nsomething\n", 37 Footer: "\n---\n\nGet images at docker.io/foo/bar:{{.Tag}}\n\n---\n\nGet GoReleaser Pro at https://goreleaser.com/pro", 38 }, 39 }) 40 ctx.ReleaseNotes = changelog 41 ctx.Git = context.GitInfo{CurrentTag: "v1.0"} 42 out, err := describeBody(ctx) 43 require.NoError(t, err) 44 45 golden.RequireEqual(t, out.Bytes()) 46 } 47 48 func TestDescribeBodyWithInvalidHeaderTemplate(t *testing.T) { 49 ctx := context.New(config.Project{ 50 Release: config.Release{ 51 Header: "## {{ .Nop }\n", 52 }, 53 }) 54 _, err := describeBody(ctx) 55 require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`) 56 } 57 58 func TestDescribeBodyWithInvalidFooterTemplate(t *testing.T) { 59 ctx := context.New(config.Project{ 60 Release: config.Release{ 61 Footer: "{{ .Nops }", 62 }, 63 }) 64 _, err := describeBody(ctx) 65 require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`) 66 }