github.phpd.cn/goreleaser/goreleaser@v0.92.0/internal/pipe/release/body_test.go (about)

     1  package release
     2  
     3  import (
     4  	"flag"
     5  	"io/ioutil"
     6  	"testing"
     7  
     8  	"github.com/goreleaser/goreleaser/internal/artifact"
     9  	"github.com/goreleaser/goreleaser/pkg/config"
    10  	"github.com/goreleaser/goreleaser/pkg/context"
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  var update = flag.Bool("update", false, "update .golden files")
    15  
    16  func TestDescribeBody(t *testing.T) {
    17  	var changelog = "feature1: description\nfeature2: other description"
    18  	var ctx = context.New(config.Project{})
    19  	ctx.ReleaseNotes = changelog
    20  	for _, d := range []string{
    21  		"goreleaser/goreleaser:0.40.0",
    22  		"goreleaser/goreleaser:latest",
    23  		"goreleaser/godownloader:v0.1.0",
    24  	} {
    25  		ctx.Artifacts.Add(artifact.Artifact{
    26  			Name: d,
    27  			Type: artifact.DockerImage,
    28  		})
    29  	}
    30  	out, err := describeBody(ctx)
    31  	assert.NoError(t, err)
    32  
    33  	var golden = "testdata/release1.golden"
    34  	if *update {
    35  		ioutil.WriteFile(golden, out.Bytes(), 0755)
    36  	}
    37  	bts, err := ioutil.ReadFile(golden)
    38  	assert.NoError(t, err)
    39  	assert.Equal(t, string(bts), out.String())
    40  }
    41  
    42  func TestDescribeBodyNoDockerImagesNoBrews(t *testing.T) {
    43  	var changelog = "feature1: description\nfeature2: other description"
    44  	var ctx = &context.Context{
    45  		ReleaseNotes: changelog,
    46  	}
    47  	out, err := describeBody(ctx)
    48  	assert.NoError(t, err)
    49  
    50  	var golden = "testdata/release2.golden"
    51  	if *update {
    52  		ioutil.WriteFile(golden, out.Bytes(), 0655)
    53  	}
    54  	bts, err := ioutil.ReadFile(golden)
    55  	assert.NoError(t, err)
    56  
    57  	assert.Equal(t, string(bts), out.String())
    58  }
    59  
    60  func TestDontEscapeHTML(t *testing.T) {
    61  	var changelog = "<h1>test</h1>"
    62  	var ctx = context.New(config.Project{})
    63  	ctx.ReleaseNotes = changelog
    64  
    65  	out, err := describeBody(ctx)
    66  	assert.NoError(t, err)
    67  	assert.Contains(t, out.String(), changelog)
    68  }