github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/internal/pipe/release/body_test.go (about)

     1  package release
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/goreleaser/goreleaser/internal/artifact"
     7  	"github.com/goreleaser/goreleaser/internal/golden"
     8  	"github.com/goreleaser/goreleaser/pkg/config"
     9  	"github.com/goreleaser/goreleaser/pkg/context"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestDescribeBody(t *testing.T) {
    14  	changelog := "feature1: description\nfeature2: other description"
    15  	ctx := context.New(config.Project{})
    16  	ctx.ReleaseNotes = changelog
    17  	for _, d := range []string{
    18  		"goreleaser/goreleaser:0.40.0",
    19  		"goreleaser/goreleaser:latest",
    20  		"goreleaser/goreleaser",
    21  		"goreleaser/godownloader:v0.1.0",
    22  	} {
    23  		ctx.Artifacts.Add(&artifact.Artifact{
    24  			Name: d,
    25  			Type: artifact.DockerImage,
    26  		})
    27  	}
    28  	out, err := describeBody(ctx)
    29  	require.NoError(t, err)
    30  
    31  	golden.RequireEqual(t, out.Bytes())
    32  }
    33  
    34  func TestDescribeBodyWithDockerManifest(t *testing.T) {
    35  	changelog := "feature1: description\nfeature2: other description"
    36  	ctx := context.New(config.Project{})
    37  	ctx.ReleaseNotes = changelog
    38  	for _, d := range []string{
    39  		"goreleaser/goreleaser:0.40.0",
    40  		"goreleaser/goreleaser:latest",
    41  		"goreleaser/godownloader:v0.1.0",
    42  	} {
    43  		ctx.Artifacts.Add(&artifact.Artifact{
    44  			Name: d,
    45  			Type: artifact.DockerManifest,
    46  		})
    47  	}
    48  	for _, d := range []string{
    49  		"goreleaser/goreleaser:0.40.0-amd64",
    50  		"goreleaser/goreleaser:latest-amd64",
    51  		"goreleaser/godownloader:v0.1.0-amd64",
    52  		"goreleaser/goreleaser:0.40.0-arm64",
    53  		"goreleaser/goreleaser:latest-arm64",
    54  		"goreleaser/godownloader:v0.1.0-arm64",
    55  	} {
    56  		ctx.Artifacts.Add(&artifact.Artifact{
    57  			Name: d,
    58  			Type: artifact.DockerImage,
    59  		})
    60  	}
    61  	out, err := describeBody(ctx)
    62  	require.NoError(t, err)
    63  
    64  	golden.RequireEqual(t, out.Bytes())
    65  }
    66  
    67  func TestDescribeBodyNoDockerImagesNoBrews(t *testing.T) {
    68  	changelog := "feature1: description\nfeature2: other description"
    69  	ctx := &context.Context{
    70  		ReleaseNotes: changelog,
    71  	}
    72  	out, err := describeBody(ctx)
    73  	require.NoError(t, err)
    74  
    75  	golden.RequireEqual(t, out.Bytes())
    76  }
    77  
    78  func TestDontEscapeHTML(t *testing.T) {
    79  	changelog := "<h1>test</h1>"
    80  	ctx := context.New(config.Project{})
    81  	ctx.ReleaseNotes = changelog
    82  
    83  	out, err := describeBody(ctx)
    84  	require.NoError(t, err)
    85  	require.Contains(t, out.String(), changelog)
    86  }
    87  
    88  func TestDescribeBodyWithHeaderAndFooter(t *testing.T) {
    89  	changelog := "feature1: description\nfeature2: other description"
    90  	ctx := context.New(config.Project{
    91  		Release: config.Release{
    92  			Header: "## Yada yada yada\nsomething\n",
    93  			Footer: "\n---\n\nGet images at docker.io/foo/bar:{{.Tag}}\n\n---\n\nGet GoReleaser Pro at https://goreleaser.com/pro",
    94  		},
    95  	})
    96  	ctx.ReleaseNotes = changelog
    97  	ctx.Git = context.GitInfo{CurrentTag: "v1.0"}
    98  	ctx.Artifacts.Add(&artifact.Artifact{
    99  		Name: "goreleaser/goreleaser:v1.2.3",
   100  		Type: artifact.DockerImage,
   101  	})
   102  	out, err := describeBody(ctx)
   103  	require.NoError(t, err)
   104  
   105  	golden.RequireEqual(t, out.Bytes())
   106  }
   107  
   108  func TestDescribeBodyWithInvalidHeaderTemplate(t *testing.T) {
   109  	ctx := context.New(config.Project{
   110  		Release: config.Release{
   111  			Header: "## {{ .Nop }\n",
   112  		},
   113  	})
   114  	_, err := describeBody(ctx)
   115  	require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
   116  }
   117  
   118  func TestDescribeBodyWithInvalidFooterTemplate(t *testing.T) {
   119  	ctx := context.New(config.Project{
   120  		Release: config.Release{
   121  			Footer: "{{ .Nops }",
   122  		},
   123  	})
   124  	_, err := describeBody(ctx)
   125  	require.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
   126  }