1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-04-11 11:42:15 +02:00
Carlos Alexandro Becker f544c5ce69
test: testctx pkg (#3807)
alternative to #3806 

the idea is that both `context.New` and `context.Context{}` are never
used in tests.

not sure yet how much I like it, so far code does look a bit more
readable though.

---------

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2023-03-02 00:01:11 -03:00

70 lines
1.8 KiB
Go

package release
import (
"testing"
"github.com/goreleaser/goreleaser/internal/golden"
"github.com/goreleaser/goreleaser/internal/testctx"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/require"
)
func TestDescribeBody(t *testing.T) {
changelog := "feature1: description\nfeature2: other description"
ctx := testctx.New()
ctx.ReleaseNotes = changelog
out, err := describeBody(ctx)
require.NoError(t, err)
golden.RequireEqual(t, out.Bytes())
}
func TestDontEscapeHTML(t *testing.T) {
changelog := "<h1>test</h1>"
ctx := testctx.New()
ctx.ReleaseNotes = changelog
out, err := describeBody(ctx)
require.NoError(t, err)
require.Contains(t, out.String(), changelog)
}
func TestDescribeBodyWithHeaderAndFooter(t *testing.T) {
changelog := "feature1: description\nfeature2: other description"
ctx := testctx.NewWithCfg(
config.Project{
Release: config.Release{
Header: "## Yada yada yada\nsomething\n",
Footer: "\n---\n\nGet images at docker.io/foo/bar:{{.Tag}}\n\n---\n\nGet GoReleaser Pro at https://goreleaser.com/pro",
},
},
testctx.WithCurrentTag("v1.0"),
func(ctx *context.Context) { ctx.ReleaseNotes = changelog },
)
out, err := describeBody(ctx)
require.NoError(t, err)
golden.RequireEqual(t, out.Bytes())
}
func TestDescribeBodyWithInvalidHeaderTemplate(t *testing.T) {
ctx := testctx.NewWithCfg(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 := testctx.NewWithCfg(config.Project{
Release: config.Release{
Footer: "{{ .Nops }",
},
})
_, err := describeBody(ctx)
require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
}