-
-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix junit format ordering Signed-off-by: L. Pivarc <[email protected]> * Make ordering stable Signed-off-by: L. Pivarc <[email protected]> * Test ordering Signed-off-by: L. Pivarc <[email protected]>
- Loading branch information
Showing
7 changed files
with
153 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/securego/gosec/v2" | ||
) | ||
|
||
var defaultIssue = gosec.Issue{ | ||
File: "/home/src/project/test.go", | ||
Line: "1", | ||
Col: "1", | ||
RuleID: "ruleID", | ||
What: "test", | ||
Confidence: gosec.High, | ||
Severity: gosec.High, | ||
Code: "1: testcode", | ||
Cwe: gosec.GetCwe("G101"), | ||
} | ||
|
||
func createIssue() gosec.Issue { | ||
return defaultIssue | ||
} | ||
|
||
func TestRules(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Sort issues Suite") | ||
} | ||
|
||
func firstIsGreater(less, greater *gosec.Issue) { | ||
slice := []*gosec.Issue{less, greater} | ||
|
||
sortIssues(slice) | ||
|
||
ExpectWithOffset(0, slice[0]).To(Equal(greater)) | ||
} | ||
|
||
var _ = Describe("Sorting by Severity", func() { | ||
It("sortes by severity", func() { | ||
less := createIssue() | ||
less.Severity = gosec.Low | ||
greater := createIssue() | ||
less.Severity = gosec.High | ||
firstIsGreater(&less, &greater) | ||
}) | ||
|
||
Context("Serverity is same", func() { | ||
It("sortes by What", func() { | ||
less := createIssue() | ||
less.What = "test1" | ||
greater := createIssue() | ||
greater.What = "test2" | ||
firstIsGreater(&less, &greater) | ||
}) | ||
}) | ||
|
||
Context("Serverity and What is same", func() { | ||
It("sortes by File", func() { | ||
less := createIssue() | ||
less.File = "test1" | ||
greater := createIssue() | ||
greater.File = "test2" | ||
|
||
firstIsGreater(&less, &greater) | ||
}) | ||
}) | ||
|
||
Context("Serverity, What and File is same", func() { | ||
It("sortes by line number", func() { | ||
less := createIssue() | ||
less.Line = "1" | ||
greater := createIssue() | ||
greater.Line = "2" | ||
|
||
firstIsGreater(&less, &greater) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters