mirror of
https://github.com/securego/gosec.git
synced 2025-11-25 22:22:17 +02:00
Refactor the rules tests to be able to configure the analyzer config per test sample
Signed-off-by: Cosmin Cojocar <cosmin.cojocar@gmx.ch>
This commit is contained in:
@@ -12,18 +12,13 @@ import (
|
||||
"github.com/securego/gosec/testutils"
|
||||
)
|
||||
|
||||
type option struct {
|
||||
name gosec.GlobalOption
|
||||
value string
|
||||
}
|
||||
|
||||
var _ = Describe("gosec rules", func() {
|
||||
|
||||
var (
|
||||
logger *log.Logger
|
||||
config gosec.Config
|
||||
analyzer *gosec.Analyzer
|
||||
runner func(string, []testutils.CodeSample, ...option)
|
||||
runner func(string, []testutils.CodeSample)
|
||||
buildTags []string
|
||||
tests bool
|
||||
)
|
||||
@@ -32,13 +27,11 @@ var _ = Describe("gosec rules", func() {
|
||||
logger, _ = testutils.NewLogger()
|
||||
config = gosec.NewConfig()
|
||||
analyzer = gosec.NewAnalyzer(config, tests, logger)
|
||||
runner = func(rule string, samples []testutils.CodeSample, options ...option) {
|
||||
for _, o := range options {
|
||||
config.SetGlobal(o.name, o.value)
|
||||
}
|
||||
runner = func(rule string, samples []testutils.CodeSample) {
|
||||
analyzer.LoadRules(rules.Generate(rules.NewRuleFilter(false, rule)).Builders())
|
||||
for n, sample := range samples {
|
||||
analyzer.Reset()
|
||||
analyzer.SetConfig(sample.Config)
|
||||
pkg := testutils.NewTestPackage()
|
||||
defer pkg.Close()
|
||||
for i, code := range sample.Code {
|
||||
@@ -75,7 +68,7 @@ var _ = Describe("gosec rules", func() {
|
||||
})
|
||||
|
||||
It("should detect errors not being checked in audit mode", func() {
|
||||
runner("G104", testutils.SampleCodeG104Audit, option{name: gosec.Audit, value: "enabled"})
|
||||
runner("G104", testutils.SampleCodeG104Audit)
|
||||
})
|
||||
|
||||
It("should detect of big.Exp function", func() {
|
||||
|
||||
Reference in New Issue
Block a user