Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flaky test results in TestOperationalRiskSimplifiedViolation test… #139

Merged
merged 2 commits into from
Aug 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions utils/resultstable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"
"sort"
"testing"

"github.com/jfrog/jfrog-cli-security/formats"
Expand Down Expand Up @@ -243,6 +244,11 @@ func TestGetOperationalRiskSimplifiedViolations(t *testing.T) {
Cadence: newFloat64Ptr(3.5), Commits: newInt64Ptr(55), Committers: newIntPtr(10), EolMessage: "no maintainers", RiskReason: "EOL"},
}
simplifiedViolations := simplifyViolations(violations, true)

// Sorting the violations based on component key so that the order will be unified for the expected results
// gav://antparent:ant:1.6.4 -> gav://antparent:ant:1.6.5 (if other tests are added, add it in order)
// In the code the violations returned from the function are being sorted at the end of the logic for printing
sortViolationsSliceBasedOnComponentVersion(simplifiedViolations)
tests := []struct {
testName string
violation services.Violation
Expand All @@ -268,6 +274,18 @@ func TestGetOperationalRiskSimplifiedViolations(t *testing.T) {
}
}

func getFirstKey(components map[string]services.Component) string {
for key := range components {
return key
}
return ""
}
func sortViolationsSliceBasedOnComponentVersion(simplifiedViolations []services.Violation) {
sort.Slice(simplifiedViolations, func(i, j int) bool {
return getFirstKey(simplifiedViolations[i].Components) < getFirstKey(simplifiedViolations[j].Components)
})
}

func TestIsImpactPathIsSubset(t *testing.T) {
testCases := []struct {
name string
Expand Down
Loading