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(engine): fixing compare e2e #6919

Merged
merged 14 commits into from
Mar 8, 2024
32 changes: 17 additions & 15 deletions e2e/utils/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import (
"golang.org/x/net/html"
)

var availablePlatforms = initPlatforms()
var (
availablePlatforms = initPlatforms()
severityIds = []string{"info", "low", "medium", "high", "total"}
headerIds = []string{"scan-paths", "scan-platforms"}
)

func initPlatforms() map[string]string {
platforms := make(map[string]string)
Expand All @@ -38,26 +42,24 @@ func HTMLValidation(t *testing.T, file string) {
require.NoError(t, errAct, "Opening Actual HTML File should not yield an error")

// Compare Header Data (Paths, Platforms)
headerIds := []string{"scan-paths", "scan-platforms"}
for arg := range headerIds {
expectedValue := getElementByID(expectedHTML, headerIds[arg])
actualValue := getElementByID(actualHTML, headerIds[arg])

sliceOfExpected := make([]string, 0, len(headerIds))
sliceOfActual := make([]string, 0, len(headerIds))
for _, header := range headerIds {
expectedValue := getElementByID(expectedHTML, header)
actualValue := getElementByID(actualHTML, header)
sliceOfActual = append(sliceOfActual, actualValue.LastChild.Data)
// Adapt path if running locally (dev)
if GetKICSDockerImageName() == "" {
expectedValue.LastChild.Data = KicsDevPathAdapter(expectedValue.LastChild.Data)
}

require.NotNil(t, actualValue.LastChild,
"[%s] Invalid value in Element ID <%s>", file, headerIds[arg])

require.Equal(t, expectedValue.LastChild.Data, actualValue.LastChild.Data,
"[%s] HTML Element <%s>:\n- Expected value: %s\n- Actual value: %s\n",
file, headerIds[arg], expectedValue.LastChild.Data, actualValue.LastChild.Data)
sliceOfExpected = append(sliceOfExpected, expectedValue.LastChild.Data)
require.NotNil(t, actualValue.LastChild, "[%s] Invalid value in Element ID <%s>", file, header)
}

require.ElementsMatch(t, sliceOfExpected, sliceOfActual,
"[%s] HTML Element :\n- Expected value: %s\n- Actual value: %s\n",
file, sliceOfExpected, sliceOfActual)
// Compare Severity Values (High, Medium, Total...)
severityIds := []string{"info", "low", "medium", "high", "total"}

for arg := range severityIds {
nodeIdentificator := "severity-count-" + severityIds[arg]
expectedSeverityValue := getElementByID(expectedHTML, nodeIdentificator)
Expand Down
8 changes: 7 additions & 1 deletion e2e/utils/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/xeipuuv/gojsonschema"
)

var filekey = "file"

type logMsg struct {
Level string `json:"level"`
ErrorMgs string `json:"error"`
Expand Down Expand Up @@ -143,7 +145,6 @@ func CheckLine(t *testing.T, expec, want string, line int) {
}

func setFields(t *testing.T, expect, actual []string, expectFileName, actualFileName, location string) {
filekey := "file"
switch location {
case "payload":
var actualI model.Documents
Expand Down Expand Up @@ -226,6 +227,11 @@ func setFields(t *testing.T, expect, actual []string, expectFileName, actualFile
})
}

require.ElementsMatch(t, expectI.ScannedPaths, actualI.ScannedPaths,
"Expected Result content: 'fixtures/%s' doesn't match the Actual Result Scanned Paths content: 'output/%s'.",
expectFileName, actualFileName)
expectI.ScannedPaths = []string{}
actualI.ScannedPaths = []string{}
require.Equal(t, expectI, actualI,
"Expected Result content: 'fixtures/%s' doesn't match the Actual Result content: 'output/%s'.",
expectFileName, actualFileName)
Expand Down
Loading