2017-04-19 16:59:26 -03:00
|
|
|
package release
|
|
|
|
|
|
|
|
import (
|
2017-12-25 20:03:40 -02:00
|
|
|
"flag"
|
2017-09-16 15:31:20 -03:00
|
|
|
"io/ioutil"
|
2017-04-19 16:59:26 -03:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2017-12-17 23:11:17 -02:00
|
|
|
"github.com/goreleaser/goreleaser/config"
|
2017-04-19 16:59:26 -03:00
|
|
|
"github.com/goreleaser/goreleaser/context"
|
2017-12-18 00:53:48 -02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
2017-04-19 16:59:26 -03:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-12-25 20:03:40 -02:00
|
|
|
var update = flag.Bool("update", false, "update .golden files")
|
|
|
|
|
2017-04-19 17:12:12 -03:00
|
|
|
func TestDescribeBody(t *testing.T) {
|
2017-04-19 16:59:26 -03:00
|
|
|
var changelog = "\nfeature1: description\nfeature2: other description"
|
2017-12-17 23: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",
|
|
|
|
} {
|
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Name: d,
|
|
|
|
Type: artifact.DockerImage,
|
|
|
|
})
|
2017-04-19 16:59:26 -03:00
|
|
|
}
|
2017-09-16 15:31:20 -03:00
|
|
|
out, err := describeBodyVersion(ctx, "go version go1.9 darwin/amd64")
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, err)
|
2017-09-16 15:31:20 -03:00
|
|
|
|
2017-12-25 20:03:40 -02:00
|
|
|
var golden = "testdata/release1.golden"
|
|
|
|
if *update {
|
|
|
|
ioutil.WriteFile(golden, out.Bytes(), 0755)
|
|
|
|
}
|
|
|
|
bts, err := ioutil.ReadFile(golden)
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, string(bts), out.String())
|
2017-09-16 15:31:20 -03:00
|
|
|
}
|
|
|
|
|
2017-12-05 18:19:18 -02:00
|
|
|
func TestDescribeBodyNoDockerImagesNoBrews(t *testing.T) {
|
2017-09-16 15:31:20 -03:00
|
|
|
var changelog = "\nfeature1: description\nfeature2: other description"
|
|
|
|
var ctx = &context.Context{
|
|
|
|
ReleaseNotes: changelog,
|
|
|
|
}
|
|
|
|
out, err := describeBodyVersion(ctx, "go version go1.9 darwin/amd64")
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, err)
|
2017-09-16 15:31:20 -03:00
|
|
|
|
2017-12-25 20:03:40 -02:00
|
|
|
var golden = "testdata/release2.golden"
|
|
|
|
if *update {
|
|
|
|
ioutil.WriteFile(golden, out.Bytes(), 0655)
|
|
|
|
}
|
|
|
|
bts, err := ioutil.ReadFile(golden)
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, err)
|
2017-09-16 15:31:20 -03:00
|
|
|
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.Equal(t, string(bts), out.String())
|
2017-04-19 16:59:26 -03:00
|
|
|
}
|
|
|
|
|
2017-07-04 09:28:26 -03:00
|
|
|
func TestDontEscapeHTML(t *testing.T) {
|
|
|
|
var changelog = "<h1>test</h1>"
|
2017-12-29 20:34:09 -02:00
|
|
|
var ctx = context.New(config.Project{})
|
|
|
|
ctx.ReleaseNotes = changelog
|
|
|
|
|
2017-07-04 09:28:26 -03:00
|
|
|
out, err := describeBody(ctx)
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, out.String(), changelog)
|
2017-07-04 09:28:26 -03:00
|
|
|
}
|
|
|
|
|
2017-04-19 16:59:26 -03:00
|
|
|
func TestGoVersionFails(t *testing.T) {
|
|
|
|
var path = os.Getenv("PATH")
|
|
|
|
defer func() {
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, os.Setenv("PATH", path))
|
2017-04-19 16:59:26 -03:00
|
|
|
}()
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, os.Setenv("PATH", ""))
|
2017-04-19 16:59:26 -03:00
|
|
|
var ctx = &context.Context{
|
2017-04-19 17:05:10 -03:00
|
|
|
ReleaseNotes: "changelog",
|
2017-04-19 16:59:26 -03:00
|
|
|
}
|
2017-04-19 17:12:12 -03:00
|
|
|
_, err := describeBody(ctx)
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.Error(t, err)
|
2017-04-19 16:59:26 -03:00
|
|
|
}
|