github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/reporting/securityVulnerability_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 TestVulnerabilityReportToMarkdown(t *testing.T) { 15 t.Parallel() 16 t.Run("success - empty", func(t *testing.T) { 17 t.Parallel() 18 vulReport := VulnerabilityReport{} 19 _, err := vulReport.ToMarkdown() 20 assert.NoError(t, err) 21 }) 22 23 t.Run("success - filled", func(t *testing.T) { 24 t.Parallel() 25 vulReport := VulnerabilityReport{ 26 BlackDuckProjectLink: "https://the.link.to.the.project.version", 27 ProjectName: "theProjectName", 28 ProjectVersion: "theProjectVersion", 29 ArtifactID: "theArtifact", 30 Branch: "main", 31 CommitID: "acb123", 32 Description: "This is the test description.", 33 DependencyType: "direct", 34 Origin: "Origin", 35 Footer: "This is the test footer", 36 Group: "the.group", 37 PipelineName: "thePipelineName", 38 PipelineLink: "https://the.link.to.the.pipeline", 39 PublishDate: "2022-06-30", 40 Resolution: "This is the test resolution.", 41 Score: 7.8, 42 Severity: "high", 43 Version: "1.2.3", 44 PackageURL: "pkg:generic/the.group/theArtifact@1.2.3", 45 VulnerabilityLink: "https://the.link/to/the/vulnerability", 46 VulnerabilityName: "CVE-Test-001", 47 } 48 goldenFilePath := filepath.Join("testdata", "markdownVulnerability.golden") 49 expected, err := os.ReadFile(goldenFilePath) 50 assert.NoError(t, err) 51 52 res, err := vulReport.ToMarkdown() 53 assert.NoError(t, err) 54 assert.Equal(t, string(expected), string(res)) 55 }) 56 }