2017-04-19 21:59:26 +02:00
|
|
|
package release
|
|
|
|
|
|
|
|
import (
|
2017-09-16 20:31:20 +02:00
|
|
|
"io/ioutil"
|
2017-04-19 21:59:26 +02:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/context"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-04-19 22:12:12 +02:00
|
|
|
func TestDescribeBody(t *testing.T) {
|
2017-04-19 21:59:26 +02:00
|
|
|
var changelog = "\nfeature1: description\nfeature2: other description"
|
|
|
|
var ctx = &context.Context{
|
2017-04-19 22:05:10 +02:00
|
|
|
ReleaseNotes: changelog,
|
2017-09-16 20:31:20 +02:00
|
|
|
Dockers: []string{
|
|
|
|
"goreleaser/goreleaser:0.40.0",
|
|
|
|
"goreleaser/godownloader:0.1.0",
|
|
|
|
},
|
2017-04-19 21:59:26 +02:00
|
|
|
}
|
2017-09-16 20:31:20 +02:00
|
|
|
out, err := describeBodyVersion(ctx, "go version go1.9 darwin/amd64")
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2017-09-16 20:31:20 +02:00
|
|
|
|
|
|
|
bts, err := ioutil.ReadFile("testdata/release1.txt")
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2017-09-26 23:50:00 +02:00
|
|
|
// ioutil.WriteFile("testdata/release1.txt", out.Bytes(), 0755)
|
2017-09-16 20:31:20 +02:00
|
|
|
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.Equal(t, string(bts), out.String())
|
2017-09-16 20:31:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDescribeBodyNoDockerImages(t *testing.T) {
|
|
|
|
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-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2017-09-16 20:31:20 +02:00
|
|
|
|
|
|
|
bts, err := ioutil.ReadFile("testdata/release2.txt")
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2017-09-26 23:50:00 +02:00
|
|
|
// ioutil.WriteFile("testdata/release2.txt", out.Bytes(), 0755)
|
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>"
|
|
|
|
var ctx = &context.Context{
|
|
|
|
ReleaseNotes: changelog,
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-04-19 21:59:26 +02:00
|
|
|
func TestGoVersionFails(t *testing.T) {
|
|
|
|
var path = os.Getenv("PATH")
|
|
|
|
defer func() {
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, os.Setenv("PATH", path))
|
2017-04-19 21:59:26 +02:00
|
|
|
}()
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, os.Setenv("PATH", ""))
|
2017-04-19 21:59:26 +02:00
|
|
|
var ctx = &context.Context{
|
2017-04-19 22:05:10 +02:00
|
|
|
ReleaseNotes: "changelog",
|
2017-04-19 21:59:26 +02:00
|
|
|
}
|
2017-04-19 22:12:12 +02:00
|
|
|
_, err := describeBody(ctx)
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.Error(t, err)
|
2017-04-19 21:59:26 +02:00
|
|
|
}
|