package plugin import ( "context" "net/http" "testing" "github.com/stretchr/testify/assert" wp "github.com/thegeeklab/wp-plugin-go/v2/plugin" ) func Test_messageContent(t *testing.T) { //nolint:lll tests := []struct { name string want string template string }{ { name: "render default template", want: "Status: **success**\nBuild: [octocat/demo](https://ci.example.com) (main) by octobot\nMessage: feat: demo commit title ([source](https://git.example.com))", template: DefaultMessageTemplate, }, { name: "render unsafe html template", want: "Status: **success**\nBuild: octocat/demo", template: "Status: **{{ .Pipeline.Status }}**\nBuild: {{ .Repository.Slug }}", }, } p := New(func(_ context.Context) error { return nil }) p.Network = wp.Network{ Context: context.Background(), Client: &http.Client{}, } p.Metadata = wp.Metadata{ Curr: wp.Commit{ Branch: "main", Title: "feat: demo commit title", URL: "https://git.example.com", Author: wp.Author{ Name: "octobot", }, }, Pipeline: wp.Pipeline{ Status: "success", URL: "https://ci.example.com", }, Repository: wp.Repository{ Slug: "octocat/demo", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p.Settings.Template = tt.template content, err := p.CreateMessage() assert.NoError(t, err) assert.Equal(t, tt.want, content) }) } }