2017-04-19 16:59:26 -03:00
|
|
|
package release
|
|
|
|
|
|
|
|
import (
|
2023-06-05 13:05:28 -03:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2017-04-19 16:59:26 -03:00
|
|
|
"testing"
|
|
|
|
|
2023-06-05 13:05:28 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
2021-05-30 21:53:40 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/golden"
|
2023-03-02 00:01:11 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testctx"
|
2023-08-24 22:06:12 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
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"
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New()
|
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>"
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New()
|
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"
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
Header: "## Yada yada yada\nsomething\n",
|
2023-06-05 13:05:28 -03:00
|
|
|
Footer: `
|
|
|
|
---
|
|
|
|
|
|
|
|
Get images at docker.io/foo/bar:{{.Tag}}
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
Get GoReleaser Pro at https://goreleaser.com/pro
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## Checksums
|
|
|
|
|
|
|
|
` + "```\n{{ .Checksums }}\n```" + `
|
|
|
|
`,
|
2023-03-02 00:01:11 -03:00
|
|
|
},
|
2021-05-30 21:53:40 -03:00
|
|
|
},
|
2023-03-02 00:01:11 -03:00
|
|
|
testctx.WithCurrentTag("v1.0"),
|
|
|
|
func(ctx *context.Context) { ctx.ReleaseNotes = changelog },
|
|
|
|
)
|
2023-06-05 13:05:28 -03:00
|
|
|
|
|
|
|
checksumPath := filepath.Join(t.TempDir(), "checksums.txt")
|
|
|
|
checksumContent := "f674623cf1edd0f753e620688cedee4e7c0e837ac1e53c0cbbce132ffe35fd52 foo.zip"
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Name: "checksums.txt",
|
|
|
|
Path: checksumPath,
|
|
|
|
Type: artifact.Checksum,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraRefresh: func() error {
|
|
|
|
return os.WriteFile(checksumPath, []byte(checksumContent), 0o644)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
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) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-07-03 19:23:29 +00:00
|
|
|
Release: config.Release{
|
|
|
|
Header: "## {{ .Nop }\n",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
_, err := describeBody(ctx)
|
2023-08-24 22:06:12 -03:00
|
|
|
testlib.RequireTemplateError(t, err)
|
2021-07-03 19:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDescribeBodyWithInvalidFooterTemplate(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-07-03 19:23:29 +00:00
|
|
|
Release: config.Release{
|
|
|
|
Footer: "{{ .Nops }",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
_, err := describeBody(ctx)
|
2023-08-24 22:06:12 -03:00
|
|
|
testlib.RequireTemplateError(t, err)
|
2021-07-03 19:23:29 +00:00
|
|
|
}
|