nitter/nitters/gitea/templates/templates_test.go

68 lines
1.3 KiB
Go
Raw Permalink Normal View History

package templates_test
import (
"embed"
"io"
"testing"
"text/template"
"github.com/golangci/golangci-lint/pkg/report"
"github.com/golangci/golangci-lint/pkg/result"
)
var (
//go:embed *
templatesFS embed.FS
templates *template.Template
)
func init() {
if tmpl, err := template.New("issue_templates").ParseFS(templatesFS, "*.tmpl.md"); err != nil {
panic(err)
} else {
templates = tmpl
}
}
func TestRenderTemplates(t *testing.T) {
t.Parallel()
tests := []struct {
name string
templateName string
templateData any
}{
{
name: "Render issue_summary.tmpl.md",
templateName: "issue_summary.tmpl.md",
templateData: map[string]any{
"Report": &report.Data{
Error: "Some error",
},
"Issue": result.Issue{
FromLinter: "Sample",
Text: "Sample description",
},
},
},
{
name: "Render issue_comment.tmpl.md",
templateName: "issue_comment.tmpl.md",
templateData: map[string]any{
"Issue": result.Issue{
FromLinter: "Sample",
Text: "Sample description",
},
},
},
}
for _, tc := range tests {
tt := tc
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if err := templates.ExecuteTemplate(io.Discard, tt.templateName, tt.templateData); err != nil {
t.Errorf("Failed to render emplate: %v", err)
}
})
}
}