2017-04-19 21:59:26 +02:00
|
|
|
package release
|
|
|
|
|
|
|
|
import (
|
2017-12-26 00:03:40 +02:00
|
|
|
"flag"
|
2017-09-16 20:31:20 +02:00
|
|
|
"io/ioutil"
|
2017-04-19 21:59:26 +02:00
|
|
|
"testing"
|
|
|
|
|
2017-12-18 04:53:48 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
2018-08-15 04:50:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2017-04-19 21:59:26 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-12-26 00:03:40 +02:00
|
|
|
var update = flag.Bool("update", false, "update .golden files")
|
|
|
|
|
2017-04-19 22:12:12 +02:00
|
|
|
func TestDescribeBody(t *testing.T) {
|
2018-04-01 18:27:57 +02:00
|
|
|
var changelog = "feature1: description\nfeature2: other description"
|
2017-12-18 03:11:17 +02:00
|
|
|
var ctx = context.New(config.Project{})
|
|
|
|
ctx.ReleaseNotes = changelog
|
|
|
|
for _, d := range []string{
|
|
|
|
"goreleaser/goreleaser:0.40.0",
|
|
|
|
"goreleaser/goreleaser:latest",
|
|
|
|
"goreleaser/godownloader:v0.1.0",
|
|
|
|
} {
|
2019-08-12 22:44:48 +02:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2017-12-18 03:11:17 +02:00
|
|
|
Name: d,
|
|
|
|
Type: artifact.DockerImage,
|
|
|
|
})
|
2017-04-19 21:59:26 +02:00
|
|
|
}
|
2018-04-01 18:27:57 +02:00
|
|
|
out, err := describeBody(ctx)
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2017-09-16 20:31:20 +02:00
|
|
|
|
2017-12-26 00:03:40 +02:00
|
|
|
var golden = "testdata/release1.golden"
|
|
|
|
if *update {
|
2018-11-29 20:43:00 +02:00
|
|
|
_ = ioutil.WriteFile(golden, out.Bytes(), 0755)
|
2017-12-26 00:03:40 +02:00
|
|
|
}
|
|
|
|
bts, err := ioutil.ReadFile(golden)
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, string(bts), out.String())
|
2017-09-16 20:31:20 +02:00
|
|
|
}
|
|
|
|
|
2017-12-05 22:19:18 +02:00
|
|
|
func TestDescribeBodyNoDockerImagesNoBrews(t *testing.T) {
|
2018-04-01 18:27:57 +02:00
|
|
|
var changelog = "feature1: description\nfeature2: other description"
|
2017-09-16 20:31:20 +02:00
|
|
|
var ctx = &context.Context{
|
|
|
|
ReleaseNotes: changelog,
|
|
|
|
}
|
2018-04-01 18:27:57 +02:00
|
|
|
out, err := describeBody(ctx)
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2017-09-16 20:31:20 +02:00
|
|
|
|
2017-12-26 00:03:40 +02:00
|
|
|
var golden = "testdata/release2.golden"
|
|
|
|
if *update {
|
2018-11-29 20:43:00 +02:00
|
|
|
_ = ioutil.WriteFile(golden, out.Bytes(), 0655)
|
2017-12-26 00:03:40 +02:00
|
|
|
}
|
|
|
|
bts, err := ioutil.ReadFile(golden)
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2017-09-16 20:31:20 +02:00
|
|
|
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.Equal(t, string(bts), out.String())
|
2017-04-19 21:59:26 +02:00
|
|
|
}
|
|
|
|
|
2017-07-04 14:28:26 +02:00
|
|
|
func TestDontEscapeHTML(t *testing.T) {
|
|
|
|
var changelog = "<h1>test</h1>"
|
2017-12-30 00:34:09 +02:00
|
|
|
var ctx = context.New(config.Project{})
|
|
|
|
ctx.ReleaseNotes = changelog
|
|
|
|
|
2017-07-04 14:28:26 +02:00
|
|
|
out, err := describeBody(ctx)
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, out.String(), changelog)
|
2017-07-04 14:28:26 +02:00
|
|
|
}
|