|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + . "github.com/onsi/ginkgo" |
| 7 | + . "github.com/onsi/gomega" |
| 8 | + "github.com/securego/gosec/v2" |
| 9 | +) |
| 10 | + |
| 11 | +var defaultIssue = gosec.Issue{ |
| 12 | + File: "/home/src/project/test.go", |
| 13 | + Line: "1", |
| 14 | + Col: "1", |
| 15 | + RuleID: "ruleID", |
| 16 | + What: "test", |
| 17 | + Confidence: gosec.High, |
| 18 | + Severity: gosec.High, |
| 19 | + Code: "1: testcode", |
| 20 | + Cwe: gosec.GetCwe("G101"), |
| 21 | +} |
| 22 | + |
| 23 | +func createIssue() gosec.Issue { |
| 24 | + return defaultIssue |
| 25 | +} |
| 26 | + |
| 27 | +func TestRules(t *testing.T) { |
| 28 | + RegisterFailHandler(Fail) |
| 29 | + RunSpecs(t, "Sort issues Suite") |
| 30 | +} |
| 31 | + |
| 32 | +func firstIsGreater(less, greater *gosec.Issue) { |
| 33 | + slice := []*gosec.Issue{less, greater} |
| 34 | + |
| 35 | + sortIssues(slice) |
| 36 | + |
| 37 | + ExpectWithOffset(0, slice[0]).To(Equal(greater)) |
| 38 | +} |
| 39 | + |
| 40 | +var _ = Describe("Sorting by Severity", func() { |
| 41 | + It("sortes by severity", func() { |
| 42 | + less := createIssue() |
| 43 | + less.Severity = gosec.Low |
| 44 | + greater := createIssue() |
| 45 | + less.Severity = gosec.High |
| 46 | + firstIsGreater(&less, &greater) |
| 47 | + }) |
| 48 | + |
| 49 | + Context("Serverity is same", func() { |
| 50 | + It("sortes by What", func() { |
| 51 | + less := createIssue() |
| 52 | + less.What = "test1" |
| 53 | + greater := createIssue() |
| 54 | + greater.What = "test2" |
| 55 | + firstIsGreater(&less, &greater) |
| 56 | + }) |
| 57 | + }) |
| 58 | + |
| 59 | + Context("Serverity and What is same", func() { |
| 60 | + It("sortes by File", func() { |
| 61 | + less := createIssue() |
| 62 | + less.File = "test1" |
| 63 | + greater := createIssue() |
| 64 | + greater.File = "test2" |
| 65 | + |
| 66 | + firstIsGreater(&less, &greater) |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
| 70 | + Context("Serverity, What and File is same", func() { |
| 71 | + It("sortes by line number", func() { |
| 72 | + less := createIssue() |
| 73 | + less.Line = "1" |
| 74 | + greater := createIssue() |
| 75 | + greater.Line = "2" |
| 76 | + |
| 77 | + firstIsGreater(&less, &greater) |
| 78 | + }) |
| 79 | + }) |
| 80 | +}) |
0 commit comments