github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/reporting/policyViolation_test.go (about) 1 //go:build unit 2 // +build unit 3 4 package reporting 5 6 import ( 7 "os" 8 "path/filepath" 9 "testing" 10 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestPolicyViolationToMarkdown(t *testing.T) { 15 t.Parallel() 16 t.Run("success - empty", func(t *testing.T) { 17 t.Parallel() 18 policyReport := PolicyViolationReport{} 19 _, err := policyReport.ToMarkdown() 20 assert.NoError(t, err) 21 }) 22 23 t.Run("success - filled", func(t *testing.T) { 24 t.Parallel() 25 policyReport := PolicyViolationReport{ 26 ArtifactID: "theArtifact", 27 Branch: "main", 28 CommitID: "acb123", 29 Description: "This is the test description.", 30 DirectDependency: "true", 31 Footer: "This is the test footer", 32 Group: "the.group", 33 PipelineName: "thePipelineName", 34 PipelineLink: "https://the.link.to.the.pipeline", 35 Version: "1.2.3", 36 PackageURL: "pkg:generic/the.group/theArtifact@1.2.3", 37 } 38 goldenFilePath := filepath.Join("testdata", "markdownPolicyViolation.golden") 39 expected, err := os.ReadFile(goldenFilePath) 40 assert.NoError(t, err) 41 42 res, err := policyReport.ToMarkdown() 43 assert.NoError(t, err) 44 assert.Equal(t, string(expected), string(res)) 45 }) 46 }