2017-04-19 16:59:26 -03:00
|
|
|
package release
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-05-30 21:53:40 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/golden"
|
2018-08-14 23:50:20 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2020-10-06 09:48:04 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-04-19 16:59:26 -03:00
|
|
|
)
|
|
|
|
|
2017-04-19 17:12:12 -03:00
|
|
|
func TestDescribeBody(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
changelog := "feature1: description\nfeature2: other description"
|
|
|
|
ctx := context.New(config.Project{})
|
2020-11-30 21:53:36 -03:00
|
|
|
ctx.ReleaseNotes = changelog
|
2018-04-01 13:27:57 -03:00
|
|
|
out, err := describeBody(ctx)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
2017-09-16 15:31:20 -03:00
|
|
|
|
2021-05-30 21:53:40 -03:00
|
|
|
golden.RequireEqual(t, out.Bytes())
|
2017-04-19 16:59:26 -03:00
|
|
|
}
|
|
|
|
|
2017-07-04 09:28:26 -03:00
|
|
|
func TestDontEscapeHTML(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
changelog := "<h1>test</h1>"
|
|
|
|
ctx := context.New(config.Project{})
|
2017-12-29 20:34:09 -02:00
|
|
|
ctx.ReleaseNotes = changelog
|
|
|
|
|
2017-07-04 09:28:26 -03:00
|
|
|
out, err := describeBody(ctx)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Contains(t, out.String(), changelog)
|
2017-07-04 09:28:26 -03:00
|
|
|
}
|
2021-05-30 21:53:40 -03:00
|
|
|
|
|
|
|
func TestDescribeBodyWithHeaderAndFooter(t *testing.T) {
|
|
|
|
changelog := "feature1: description\nfeature2: other description"
|
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
Header: "## Yada yada yada\nsomething\n",
|
2021-07-03 09:42:54 -07:00
|
|
|
Footer: "\n---\n\nGet images at docker.io/foo/bar:{{.Tag}}\n\n---\n\nGet GoReleaser Pro at https://goreleaser.com/pro",
|
2021-05-30 21:53:40 -03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.ReleaseNotes = changelog
|
2021-07-03 09:42:54 -07:00
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0"}
|
2021-05-30 21:53:40 -03:00
|
|
|
out, err := describeBody(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
golden.RequireEqual(t, out.Bytes())
|
|
|
|
}
|
2021-07-03 19:23:29 +00:00
|
|
|
|
|
|
|
func TestDescribeBodyWithInvalidHeaderTemplate(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
Header: "## {{ .Nop }\n",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
_, err := describeBody(ctx)
|
|
|
|
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDescribeBodyWithInvalidFooterTemplate(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
Footer: "{{ .Nops }",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
_, err := describeBody(ctx)
|
|
|
|
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
|
|
|
|
}
|