From c36187f8559bc8f8cf81298a62aee8e9dd292a7b Mon Sep 17 00:00:00 2001 From: cx-leonardo-fontes <204389152+cx-leonardo-fontes@users.noreply.github.com> Date: Fri, 23 Jan 2026 15:28:18 +0000 Subject: [PATCH 1/2] fix struct from public interface in an internal package and removed nested ScanConfig inside EngineConfig --- cmd/config.go | 2 +- cmd/main_test.go | 5 +-- engine/engine.go | 13 ++++---- engine/engine_test.go | 13 +++----- internal/resources/scanner.go | 17 ---------- pkg/scan.go | 11 +++---- pkg/scan_test.go | 61 +++++++++++++++++------------------ pkg/scanner.go | 23 ++++++++++--- 8 files changed, 66 insertions(+), 79 deletions(-) delete mode 100644 internal/resources/scanner.go diff --git a/cmd/config.go b/cmd/config.go index b05c63c4..22b9e541 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -37,7 +37,7 @@ func processFlags(rootCmd *cobra.Command) error { } // Apply all flag mappings immediately - engineConfigVar.ScanConfig.WithValidation = validateVar + engineConfigVar.WithValidation = validateVar if len(customRegexRuleVar) > 0 { engineConfigVar.CustomRegexPatterns = customRegexRuleVar } diff --git a/cmd/main_test.go b/cmd/main_test.go index 0bf08f0f..382c7592 100644 --- a/cmd/main_test.go +++ b/cmd/main_test.go @@ -8,7 +8,6 @@ import ( "github.com/checkmarx/2ms/v5/engine" "github.com/checkmarx/2ms/v5/engine/rules/ruledefine" - "github.com/checkmarx/2ms/v5/internal/resources" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" ) @@ -44,9 +43,7 @@ func TestPreRun(t *testing.T) { stdoutFormatVar: "json", reportPath: []string{"mock.json"}, engineConfigVar: engine.EngineConfig{ - ScanConfig: resources.ScanConfig{ - WithValidation: true, - }, + WithValidation: true, }, expectedPreRunErr: nil, }, diff --git a/engine/engine.go b/engine/engine.go index 8ad7e7f3..d99a65a8 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -27,7 +27,6 @@ import ( "github.com/checkmarx/2ms/v5/engine/score" "github.com/checkmarx/2ms/v5/engine/semaphore" "github.com/checkmarx/2ms/v5/engine/validation" - "github.com/checkmarx/2ms/v5/internal/resources" "github.com/checkmarx/2ms/v5/internal/workerpool" "github.com/checkmarx/2ms/v5/lib/reporting" "github.com/checkmarx/2ms/v5/lib/secrets" @@ -88,7 +87,7 @@ type Engine struct { Report reporting.IReport - ScanConfig resources.ScanConfig + WithValidation bool wg conc.WaitGroup @@ -151,7 +150,7 @@ type EngineConfig struct { CustomRules []*ruledefine.Rule - ScanConfig resources.ScanConfig + WithValidation bool } type EngineOption func(*Engine) @@ -185,7 +184,7 @@ func initEngine(engineConfig *EngineConfig, opts ...EngineOption) (*Engine, erro return nil, ErrNoRulesSelected } - scorer := score.NewScorer(finalRules, engineConfig.ScanConfig.WithValidation) + scorer := score.NewScorer(finalRules, engineConfig.WithValidation) fileWalkerWorkerPoolSize := defaultDetectorWorkerPoolSize if engineConfig.DetectorWorkerPoolSize > 0 { @@ -217,7 +216,7 @@ func initEngine(engineConfig *EngineConfig, opts ...EngineOption) (*Engine, erro ignoredIds: &engineConfig.IgnoredIds, allowedValues: &engineConfig.AllowedValues, - ScanConfig: engineConfig.ScanConfig, + WithValidation: engineConfig.WithValidation, secretsChan: make(chan *secrets.Secret, runtime.GOMAXPROCS(0)), secretsExtrasChan: make(chan *secrets.Secret, runtime.GOMAXPROCS(0)), @@ -703,7 +702,7 @@ func (e *Engine) consumeItems(pluginName string) { } func (e *Engine) processSecrets() { - if e.ScanConfig.WithValidation { + if e.WithValidation { e.processSecretsWithValidation() } else { e.processSecretsWithoutValidation() @@ -756,7 +755,7 @@ func (e *Engine) processEvaluationWithoutValidation() { // processSecretsEvaluation evaluates the secret's validationStatus, Severity and CVSS score func (e *Engine) processSecretsEvaluation() { - if e.ScanConfig.WithValidation { + if e.WithValidation { e.processEvaluationWithValidation() } else { e.processEvaluationWithoutValidation() diff --git a/engine/engine_test.go b/engine/engine_test.go index 2009d0ad..2f08030f 100644 --- a/engine/engine_test.go +++ b/engine/engine_test.go @@ -21,7 +21,6 @@ import ( "github.com/checkmarx/2ms/v5/engine/chunk" "github.com/checkmarx/2ms/v5/engine/rules" "github.com/checkmarx/2ms/v5/engine/semaphore" - "github.com/checkmarx/2ms/v5/internal/resources" "github.com/checkmarx/2ms/v5/lib/secrets" "github.com/checkmarx/2ms/v5/plugins" "github.com/rs/zerolog" @@ -939,9 +938,7 @@ func TestProcessItems(t *testing.T) { func TestProcessSecrets(t *testing.T) { t.Run("Validate flag is enabled", func(t *testing.T) { instance, err := initEngine(&EngineConfig{ - ScanConfig: resources.ScanConfig{ - WithValidation: true, - }, + WithValidation: true, }) assert.NoError(t, err) secretsChan := instance.secretsChan @@ -993,9 +990,7 @@ func TestProcessSecrets(t *testing.T) { }) t.Run("Validate flag is disabled", func(t *testing.T) { instance, err := initEngine(&EngineConfig{ - ScanConfig: resources.ScanConfig{ - WithValidation: false, - }, + WithValidation: false, }) assert.NoError(t, err) secretsChan := instance.secretsChan @@ -1207,8 +1202,8 @@ func TestProcessEvaluationWithValidation(t *testing.T) { t.Run(tt.name, func(t *testing.T) { instance, err := initEngine( &EngineConfig{ - ScanConfig: resources.ScanConfig{WithValidation: true}, - CustomRules: tt.customRules}, + WithValidation: true, + CustomRules: tt.customRules}, ) assert.NoError(t, err) validationChan := instance.GetValidationCh() diff --git a/internal/resources/scanner.go b/internal/resources/scanner.go deleted file mode 100644 index 04985250..00000000 --- a/internal/resources/scanner.go +++ /dev/null @@ -1,17 +0,0 @@ -package resources - -import "github.com/checkmarx/2ms/v5/engine/rules/ruledefine" - -type ScanConfig struct { - IgnoreResultIds []string - SelectRules []string - IgnoreRules []string - CustomRules []*ruledefine.Rule - WithValidation bool - PluginName string - - // Limit settings - MaxFindings uint64 // Total findings limit across entire scan (0 = no limit) - MaxRuleMatchesPerFragment uint64 // Regex matches limit per rule per fragment (0 = no limit) - MaxSecretSize uint64 // Maximum secret size in bytes (0 = no limit) -} diff --git a/pkg/scan.go b/pkg/scan.go index f5d63a23..ab35914e 100644 --- a/pkg/scan.go +++ b/pkg/scan.go @@ -5,7 +5,6 @@ import ( "fmt" "sync" - "github.com/checkmarx/2ms/v5/internal/resources" "github.com/checkmarx/2ms/v5/plugins" "github.com/rs/zerolog/log" "github.com/sourcegraph/conc" @@ -17,7 +16,7 @@ import ( type scanner struct { engineInstance engine.IEngine - scanConfig resources.ScanConfig + scanConfig ScanConfig mu sync.RWMutex } @@ -33,7 +32,7 @@ func NewScanner() Scanner { return &scanner{} } -func (s *scanner) Reset(scanConfig *resources.ScanConfig, opts ...engine.EngineOption) error { +func (s *scanner) Reset(scanConfig *ScanConfig, opts ...engine.EngineOption) error { s.mu.Lock() defer s.mu.Unlock() @@ -45,7 +44,7 @@ func (s *scanner) Reset(scanConfig *resources.ScanConfig, opts ...engine.EngineO MaxFindings: scanConfig.MaxFindings, MaxRuleMatchesPerFragment: scanConfig.MaxRuleMatchesPerFragment, MaxSecretSize: scanConfig.MaxSecretSize, - ScanConfig: *scanConfig, + WithValidation: scanConfig.WithValidation, }, opts...) if err != nil { return fmt.Errorf("error initializing engine: %w", err) @@ -57,7 +56,7 @@ func (s *scanner) Reset(scanConfig *resources.ScanConfig, opts ...engine.EngineO return nil } -func (s *scanner) Scan(scanItems []ScanItem, scanConfig *resources.ScanConfig, opts ...engine.EngineOption) (reporting.IReport, error) { +func (s *scanner) Scan(scanItems []ScanItem, scanConfig *ScanConfig, opts ...engine.EngineOption) (reporting.IReport, error) { var wg conc.WaitGroup err := s.Reset(scanConfig, opts...) if err != nil { @@ -109,7 +108,7 @@ func (s *scanner) Scan(scanItems []ScanItem, scanConfig *resources.ScanConfig, o func (s *scanner) ScanDynamic( itemsIn <-chan ScanItem, - scanConfig *resources.ScanConfig, + scanConfig *ScanConfig, opts ...engine.EngineOption, ) (reporting.IReport, error) { var wg conc.WaitGroup diff --git a/pkg/scan_test.go b/pkg/scan_test.go index 1d9b6bf5..83fad40d 100644 --- a/pkg/scan_test.go +++ b/pkg/scan_test.go @@ -10,7 +10,6 @@ import ( "github.com/checkmarx/2ms/v5/engine" "github.com/checkmarx/2ms/v5/engine/rules" "github.com/checkmarx/2ms/v5/engine/rules/ruledefine" - "github.com/checkmarx/2ms/v5/internal/resources" "github.com/checkmarx/2ms/v5/lib/reporting" "github.com/checkmarx/2ms/v5/lib/secrets" "github.com/checkmarx/2ms/v5/lib/utils" @@ -121,7 +120,7 @@ func TestScan(t *testing.T) { } testScanner := NewScanner() - actualReport, err := testScanner.Scan(scanItems, &resources.ScanConfig{}) + actualReport, err := testScanner.Scan(scanItems, &ScanConfig{}) assert.NoError(t, err, "scanner encountered an error") // Use helper function to either update expected file or compare results @@ -158,7 +157,7 @@ func TestScan(t *testing.T) { } testScanner := NewScanner() - actualReport, err := testScanner.Scan(scanItems, &resources.ScanConfig{ + actualReport, err := testScanner.Scan(scanItems, &ScanConfig{ IgnoreResultIds: []string{ "efc9a9ee89f1d732c7321067eb701b9656e91f15", "c31705d99e835e4ac7bc3f688bd9558309e056ed", @@ -218,7 +217,7 @@ func TestScan(t *testing.T) { } testScanner := NewScanner() - actualReport, err := testScanner.Scan(scanItems, &resources.ScanConfig{ + actualReport, err := testScanner.Scan(scanItems, &ScanConfig{ IgnoreRules: []string{ "github-pat", }, @@ -271,7 +270,7 @@ func TestScan(t *testing.T) { errorsCh <- fmt.Errorf("mock processing error 1") errorsCh <- fmt.Errorf("mock processing error 2") }() - report, err := testScanner.Scan(scanItems, &resources.ScanConfig{}, engine.WithPluginChannels(pluginChannels)) + report, err := testScanner.Scan(scanItems, &ScanConfig{}, engine.WithPluginChannels(pluginChannels)) assert.Equal(t, 0, report.GetTotalItemsScanned()) assert.Equal(t, 0, report.GetTotalSecretsFound()) @@ -282,7 +281,7 @@ func TestScan(t *testing.T) { }) t.Run("scan with scanItems empty", func(t *testing.T) { testScanner := NewScanner() - actualReport, err := testScanner.Scan([]ScanItem{}, &resources.ScanConfig{}) + actualReport, err := testScanner.Scan([]ScanItem{}, &ScanConfig{}) assert.NoError(t, err, "scanner encountered an error") assert.Equal(t, 0, actualReport.GetTotalItemsScanned()) assert.Equal(t, 0, actualReport.GetTotalSecretsFound()) @@ -291,7 +290,7 @@ func TestScan(t *testing.T) { }) t.Run("scan with scanItems nil", func(t *testing.T) { testScanner := NewScanner() - actualReport, err := testScanner.Scan(nil, &resources.ScanConfig{}) + actualReport, err := testScanner.Scan(nil, &ScanConfig{}) assert.NoError(t, err, "scanner encountered an error") assert.Equal(t, 0, actualReport.GetTotalItemsScanned()) assert.Equal(t, 0, actualReport.GetTotalSecretsFound()) @@ -329,7 +328,7 @@ func TestScan(t *testing.T) { } testScanner := NewScanner() - actualReport, err := testScanner.Scan(scanItems, &resources.ScanConfig{}) + actualReport, err := testScanner.Scan(scanItems, &ScanConfig{}) assert.NoError(t, err, "scanner encountered an error") // scan 1 @@ -357,7 +356,7 @@ func TestScan(t *testing.T) { assert.EqualValues(t, normalizedExpectedReport, normalizedActualReport) // scan 2 - actualReport, err = testScanner.Scan(scanItems, &resources.ScanConfig{ + actualReport, err = testScanner.Scan(scanItems, &ScanConfig{ IgnoreResultIds: []string{ "efc9a9ee89f1d732c7321067eb701b9656e91f15", "c31705d99e835e4ac7bc3f688bd9558309e056ed", @@ -427,14 +426,14 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { tests := []struct { Name string - ScanConfig *resources.ScanConfig + ScanConfig *ScanConfig ScanItems []ScanItem ExpectedReportPath string expectErrors []error }{ { Name: "Run all default + custom rules", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: cloneRules(customRules), WithValidation: true, }, @@ -444,7 +443,7 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { }, { Name: "Run only custom rules", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: cloneRules(customRules), WithValidation: true, SelectRules: []string{"custom"}, @@ -455,7 +454,7 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { }, { Name: "Run only custom override rules", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: cloneRules(customRules), WithValidation: true, SelectRules: []string{"override"}, @@ -466,7 +465,7 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { }, { Name: "Run default + non override rules", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: cloneRules(customRules), WithValidation: true, IgnoreRules: []string{"override"}, @@ -477,7 +476,7 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { }, { Name: "Run only custom rules and ignore overrides", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: cloneRules(customRules), WithValidation: true, SelectRules: []string{"custom"}, @@ -489,7 +488,7 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { }, { Name: "Run only default rules by ignoring custom rules", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: cloneRules(customRules), WithValidation: true, IgnoreRules: []string{"custom"}, @@ -500,7 +499,7 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { }, { Name: "Run only custom rules by ignoring custom rules by id", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: cloneRules(customRules), WithValidation: true, SelectRules: []string{"custom"}, @@ -515,7 +514,7 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { }, { Name: "Run only custom rules by ignoring custom rules by name", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: cloneRules(customRules), WithValidation: true, SelectRules: []string{"custom"}, @@ -530,7 +529,7 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { }, { Name: "Run only custom rules by ignoring override result Ids", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: cloneRules(customRules), WithValidation: true, SelectRules: []string{"custom"}, @@ -546,7 +545,7 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { }, { Name: "Rule name, id, regex missing", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: []*ruledefine.Rule{ { Description: "Match passwords", @@ -568,7 +567,7 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { }, { Name: "Regex, severity and score parameters invalid", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: []*ruledefine.Rule{ { RuleID: "db18ccf1-4fbf-49f6-aec1-939a2e5464c0", @@ -600,7 +599,7 @@ func TestScanAndScanDynamicWithCustomRules(t *testing.T) { }, { Name: "Rule id missing", - ScanConfig: &resources.ScanConfig{ + ScanConfig: &ScanConfig{ CustomRules: []*ruledefine.Rule{ { RuleName: "mock-rule", @@ -699,7 +698,7 @@ func TestScanDynamic(t *testing.T) { testScanner := NewScanner() assert.NoError(t, err, "failed to create scanner") - actualReport, err := testScanner.ScanDynamic(itemsIn, &resources.ScanConfig{}) + actualReport, err := testScanner.ScanDynamic(itemsIn, &ScanConfig{}) assert.NoError(t, err, "scanner encountered an error") compareOrUpdateTestData(t, actualReport, expectedReportPath) @@ -743,7 +742,7 @@ func TestScanDynamic(t *testing.T) { testScanner := NewScanner() - actualReport, err := testScanner.ScanDynamic(itemsIn, &resources.ScanConfig{ + actualReport, err := testScanner.ScanDynamic(itemsIn, &ScanConfig{ IgnoreResultIds: []string{ "efc9a9ee89f1d732c7321067eb701b9656e91f15", "c31705d99e835e4ac7bc3f688bd9558309e056ed", @@ -792,7 +791,7 @@ func TestScanDynamic(t *testing.T) { testScanner := NewScanner() assert.NoError(t, err, "failed to create scanner") - actualReport, err := testScanner.ScanDynamic(itemsIn, &resources.ScanConfig{ + actualReport, err := testScanner.ScanDynamic(itemsIn, &ScanConfig{ IgnoreRules: []string{ "github-pat", }, @@ -820,7 +819,7 @@ func TestScanDynamic(t *testing.T) { testScanner := NewScanner() - report, err := testScanner.ScanDynamic(itemsIn, &resources.ScanConfig{IgnoreRules: idOfRules}) + report, err := testScanner.ScanDynamic(itemsIn, &ScanConfig{IgnoreRules: idOfRules}) assert.Error(t, err) assert.ErrorIs(t, err, engine.ErrNoRulesSelected) @@ -870,7 +869,7 @@ func TestScanDynamic(t *testing.T) { testScanner := NewScanner() // scan 2 - actualReport, err := testScanner.ScanDynamic(itemsIn1, &resources.ScanConfig{}) + actualReport, err := testScanner.ScanDynamic(itemsIn1, &ScanConfig{}) assert.NoError(t, err, "scanner encountered an error") expectedReportBytes, err := os.ReadFile(expectedReportPath) @@ -896,7 +895,7 @@ func TestScanDynamic(t *testing.T) { assert.EqualValues(t, normalizedExpectedReport, normalizedActualReport) // scan 2 - actualReport, err = testScanner.ScanDynamic(itemsIn2, &resources.ScanConfig{ + actualReport, err = testScanner.ScanDynamic(itemsIn2, &ScanConfig{ IgnoreResultIds: []string{ "efc9a9ee89f1d732c7321067eb701b9656e91f15", "c31705d99e835e4ac7bc3f688bd9558309e056ed", @@ -958,7 +957,7 @@ func TestScanWithValidation(t *testing.T) { } testScanner := NewScanner() - actualReport, err := testScanner.Scan(scanItems, &resources.ScanConfig{WithValidation: true}) + actualReport, err := testScanner.Scan(scanItems, &ScanConfig{WithValidation: true}) assert.NoError(t, err, "scanner encountered an error") expectedReportBytes, err := os.ReadFile(expectedReportWithValidationPath) @@ -1109,7 +1108,7 @@ func TestScan_LimitSettings(t *testing.T) { } testScanner := NewScanner() - actualReport, err := testScanner.Scan(scanItems, &resources.ScanConfig{ + actualReport, err := testScanner.Scan(scanItems, &ScanConfig{ MaxFindings: tt.maxFindings, MaxRuleMatchesPerFragment: tt.maxRuleMatchesPerFragment, MaxSecretSize: tt.maxSecretSize, @@ -1215,7 +1214,7 @@ func TestScanDynamic_LimitSettings(t *testing.T) { close(itemsIn) testScanner := NewScanner() - actualReport, err := testScanner.ScanDynamic(itemsIn, &resources.ScanConfig{ + actualReport, err := testScanner.ScanDynamic(itemsIn, &ScanConfig{ MaxFindings: tt.maxFindings, MaxRuleMatchesPerFragment: tt.maxRuleMatchesPerFragment, MaxSecretSize: tt.maxSecretSize, diff --git a/pkg/scanner.go b/pkg/scanner.go index a0e6b977..33b22492 100644 --- a/pkg/scanner.go +++ b/pkg/scanner.go @@ -2,11 +2,26 @@ package scanner import ( "github.com/checkmarx/2ms/v5/engine" - "github.com/checkmarx/2ms/v5/internal/resources" + "github.com/checkmarx/2ms/v5/engine/rules/ruledefine" "github.com/checkmarx/2ms/v5/lib/reporting" "github.com/checkmarx/2ms/v5/plugins" ) +// ScanConfig contains configuration options for scanning. +type ScanConfig struct { + IgnoreResultIds []string + SelectRules []string + IgnoreRules []string + CustomRules []*ruledefine.Rule + WithValidation bool + PluginName string + + // Limit settings + MaxFindings uint64 // Total findings limit across entire scan (0 = no limit) + MaxRuleMatchesPerFragment uint64 // Regex matches limit per rule per fragment (0 = no limit) + MaxSecretSize uint64 // Maximum secret size in bytes (0 = no limit) +} + type ScanItem struct { Content *string // Unique identifier of the item @@ -34,8 +49,8 @@ func (i ScanItem) GetGitInfo() *plugins.GitInfo { } type Scanner interface { - Reset(scanConfig *resources.ScanConfig, opts ...engine.EngineOption) error - Scan(scanItems []ScanItem, scanConfig *resources.ScanConfig, opts ...engine.EngineOption) (reporting.IReport, error) + Reset(scanConfig *ScanConfig, opts ...engine.EngineOption) error + Scan(scanItems []ScanItem, scanConfig *ScanConfig, opts ...engine.EngineOption) (reporting.IReport, error) // ScanDynamic performs a scans with custom input of items and optional custom plugin channels. // // To provide custom plugin channels, use engine.WithPluginChannels: @@ -44,5 +59,5 @@ type Scanner interface { // c.Items = make(chan plugins.ISourceItem, 100) // }) // s.ScanDynamic(ScanConfig{}, engine.WithPluginChannels(pluginChannels)) - ScanDynamic(itemsIn <-chan ScanItem, scanConfig *resources.ScanConfig, opts ...engine.EngineOption) (reporting.IReport, error) + ScanDynamic(itemsIn <-chan ScanItem, scanConfig *ScanConfig, opts ...engine.EngineOption) (reporting.IReport, error) } From 8876a1bbcc8bced5e100f40dc24503eea7e14cb8 Mon Sep 17 00:00:00 2001 From: cx-leonardo-fontes <204389152+cx-leonardo-fontes@users.noreply.github.com> Date: Fri, 23 Jan 2026 15:43:11 +0000 Subject: [PATCH 2/2] fix tests --- cmd/config_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/config_test.go b/cmd/config_test.go index 3b16f7c6..3c0a8477 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -126,7 +126,7 @@ func TestProcessFlags(t *testing.T) { t.Run("ValidateVarMapping", func(t *testing.T) { // Reset global variables validateVar = false - engineConfigVar.ScanConfig.WithValidation = false + engineConfigVar.WithValidation = false // Set test value validateVar = true @@ -137,7 +137,7 @@ func TestProcessFlags(t *testing.T) { processFlags(rootCmd) // Verify mapping - assert.Equal(t, validateVar, engineConfigVar.ScanConfig.WithValidation, "validateVar should be mapped to engineConfigVar.ScanConfig.WithValidation") + assert.Equal(t, validateVar, engineConfigVar.WithValidation, "validateVar should be mapped to engineConfigVar.WithValidation") }) t.Run("IgnoreListProcessing", func(t *testing.T) { @@ -170,7 +170,7 @@ func TestProcessFlags(t *testing.T) { // Verify all mappings assert.Equal(t, customRegexRuleVar, engineConfigVar.CustomRegexPatterns, "Custom regex patterns should be mapped") - assert.Equal(t, validateVar, engineConfigVar.ScanConfig.WithValidation, "Validation flag should be mapped") + assert.Equal(t, validateVar, engineConfigVar.WithValidation, "Validation flag should be mapped") assert.Equal(t, []string{"ignored-rule"}, engineConfigVar.IgnoreList, "IgnoreList should be preserved") assert.Equal(t, 50, engineConfigVar.MaxTargetMegabytes, "MaxTargetMegabytes should be preserved") }) @@ -181,7 +181,7 @@ func TestProcessFlags(t *testing.T) { validateVar = false engineConfigVar.IgnoreList = []string{} engineConfigVar.CustomRegexPatterns = []string{} - engineConfigVar.ScanConfig.WithValidation = false + engineConfigVar.WithValidation = false // Process flags rootCmd := &cobra.Command{Use: "test"} @@ -190,7 +190,7 @@ func TestProcessFlags(t *testing.T) { // Verify empty values are handled correctly assert.Empty(t, engineConfigVar.CustomRegexPatterns, "Empty custom regex patterns should remain empty") - assert.False(t, engineConfigVar.ScanConfig.WithValidation, "Validation should be false by default") + assert.False(t, engineConfigVar.WithValidation, "Validation should be false by default") assert.Empty(t, engineConfigVar.IgnoreList, "Empty ignore list should remain empty") }) } @@ -220,7 +220,7 @@ max-target-megabytes: 10` processFlags(rootCmd) // Verify CLI values take precedence - assert.True(t, engineConfigVar.ScanConfig.WithValidation, "CLI validate flag should override config file") + assert.True(t, engineConfigVar.WithValidation, "CLI validate flag should override config file") assert.Equal(t, zerolog.DebugLevel, log.Logger.GetLevel(), "CLI log level should override config file") }) }