Skip to content

Commit

Permalink
added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
BenAlvo1 committed Aug 20, 2024
1 parent dade2e4 commit cc90033
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions internal/commands/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/checkmarx/ast-cli/internal/commands/util/printer"
errorConstants "github.com/checkmarx/ast-cli/internal/constants/errors"
"github.com/checkmarx/ast-cli/internal/params"
commonParams "github.com/checkmarx/ast-cli/internal/params"

Check failure on line 16 in internal/commands/result_test.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "github.com/checkmarx/ast-cli/internal/params" (stylecheck)
"github.com/checkmarx/ast-cli/internal/wrappers"
"github.com/checkmarx/ast-cli/internal/wrappers/mock"
"gotest.tools/assert"
Expand Down Expand Up @@ -973,3 +974,89 @@ func TestGetResultsSummaryConsoleFormatWithCriticalDisabled(t *testing.T) {

mock.SetScsMockVarsToDefault()
}

func Test_enhanceWithScanSummary(t *testing.T) {
tests := []struct {
name string
summary *wrappers.ResultSummary
results *wrappers.ScanResultsCollection
featureFlagsWrapper wrappers.FeatureFlagsWrapper
expectedIssues int
}{
{
name: "scan summary with no vulnerabilities",
summary: createEmptyResultSummary(),
results: &wrappers.ScanResultsCollection{
Results: nil,
TotalCount: 0,
ScanID: "MOCK",
},
featureFlagsWrapper: mock.FeatureFlagsMockWrapper{},
expectedIssues: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
enhanceWithScanSummary(tt.summary, tt.results, tt.featureFlagsWrapper)

Check failure on line 1000 in internal/commands/result_test.go

View workflow job for this annotation

GitHub Actions / lint

Using the variable on range scope `tt` in function literal (scopelint)
assert.Equal(t, tt.expectedIssues, tt.summary.TotalIssues)

Check failure on line 1001 in internal/commands/result_test.go

View workflow job for this annotation

GitHub Actions / lint

Using the variable on range scope `tt` in function literal (scopelint)
})
}
}

func createEmptyResultSummary() *wrappers.ResultSummary {
return &wrappers.ResultSummary{
TotalIssues: 0,
CriticalIssues: 0,
HighIssues: 0,
MediumIssues: 0,
LowIssues: 0,
InfoIssues: 0,
SastIssues: 0,
ScaIssues: 0,
KicsIssues: 0,
ScsIssues: 0,
SCSOverview: wrappers.SCSOverview{},
APISecurity: wrappers.APISecResult{
APICount: 0,
TotalRisksCount: 0,
Risks: []int{0, 0, 0, 0},
StatusCode: 0,
},
EnginesEnabled: []string{"sast", "sca", "kics", "containers"},
EnginesResult: wrappers.EnginesResultsSummary{
Sast: &wrappers.EngineResultSummary{
Critical: 0,
High: 0,
Medium: 0,
Low: 0,
Info: 0,
},
commonParams.ScaType: &wrappers.EngineResultSummary{
Critical: 0,
High: 0,
Medium: 0,
Low: 0,
Info: 0,
},
commonParams.KicsType: &wrappers.EngineResultSummary{
Critical: 0,
High: 0,
Medium: 0,
Low: 0,
Info: 0,
},
commonParams.APISecType: &wrappers.EngineResultSummary{
Critical: 0,
High: 0,
Medium: 0,
Low: 0,
},
commonParams.ContainersType: &wrappers.EngineResultSummary{
Critical: 0,
High: 0,
Medium: 0,
Low: 0,
},
},
}
}

0 comments on commit cc90033

Please sign in to comment.