From c8a0f5fdd9be34ebcb958a8070db556a8b86d3a0 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Fri, 1 Mar 2024 11:46:34 +0000 Subject: [PATCH 01/10] fixing compare e2e --- e2e/utils/html.go | 2 +- e2e/utils/json.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/utils/html.go b/e2e/utils/html.go index 82f40568b35..5e6e91e4df3 100644 --- a/e2e/utils/html.go +++ b/e2e/utils/html.go @@ -51,7 +51,7 @@ func HTMLValidation(t *testing.T, file string) { require.NotNil(t, actualValue.LastChild, "[%s] Invalid value in Element ID <%s>", file, headerIds[arg]) - require.Equal(t, expectedValue.LastChild.Data, actualValue.LastChild.Data, + require.ElementsMatch(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) } diff --git a/e2e/utils/json.go b/e2e/utils/json.go index 1f9acbc0eb4..20a16972e87 100644 --- a/e2e/utils/json.go +++ b/e2e/utils/json.go @@ -226,7 +226,7 @@ func setFields(t *testing.T, expect, actual []string, expectFileName, actualFile }) } - require.Equal(t, expectI, actualI, + require.ElementsMatch(t, expectI, actualI, "Expected Result content: 'fixtures/%s' doesn't match the Actual Result content: 'output/%s'.", expectFileName, actualFileName) } From c19a36c3857e18263becf2d168d7286adc568cef Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Fri, 1 Mar 2024 13:03:17 +0000 Subject: [PATCH 02/10] test --- e2e/utils/html.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/e2e/utils/html.go b/e2e/utils/html.go index 5e6e91e4df3..8d584da8c68 100644 --- a/e2e/utils/html.go +++ b/e2e/utils/html.go @@ -39,23 +39,23 @@ func HTMLValidation(t *testing.T, file string) { // 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([]html.Node, 0, len(headerIds)) + sliceOfActual := make([]html.Node, 0, len(headerIds)) + for _, header := range headerIds { + expectedValue := getElementByID(expectedHTML, header) + sliceOfExpected = append(sliceOfExpected, *expectedValue) + actualValue := getElementByID(actualHTML, header) + sliceOfActual = append(sliceOfActual, *actualValue) // 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.ElementsMatch(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) + 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 { From aeb0070a7857b8a0682ff2d9923398738866edb8 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Fri, 1 Mar 2024 14:20:31 +0000 Subject: [PATCH 03/10] clean code --- e2e/utils/html.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/e2e/utils/html.go b/e2e/utils/html.go index 8d584da8c68..270d70c208a 100644 --- a/e2e/utils/html.go +++ b/e2e/utils/html.go @@ -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) @@ -38,14 +42,13 @@ 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"} - sliceOfExpected := make([]html.Node, 0, len(headerIds)) - sliceOfActual := make([]html.Node, 0, len(headerIds)) + sliceOfExpected := make([]string, 0, len(headerIds)) + sliceOfActual := make([]string, 0, len(headerIds)) for _, header := range headerIds { expectedValue := getElementByID(expectedHTML, header) - sliceOfExpected = append(sliceOfExpected, *expectedValue) + sliceOfExpected = append(sliceOfExpected, expectedValue.LastChild.Data) actualValue := getElementByID(actualHTML, header) - sliceOfActual = append(sliceOfActual, *actualValue) + sliceOfActual = append(sliceOfActual, actualValue.LastChild.Data) // Adapt path if running locally (dev) if GetKICSDockerImageName() == "" { @@ -57,7 +60,7 @@ func HTMLValidation(t *testing.T, file string) { "[%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) From ef2cd84030286b83ebdf5a61270d0e175d32714c Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Fri, 1 Mar 2024 14:29:42 +0000 Subject: [PATCH 04/10] force --- e2e/utils/html.go | 1 - 1 file changed, 1 deletion(-) diff --git a/e2e/utils/html.go b/e2e/utils/html.go index 270d70c208a..233ee93abd4 100644 --- a/e2e/utils/html.go +++ b/e2e/utils/html.go @@ -49,7 +49,6 @@ func HTMLValidation(t *testing.T, file string) { sliceOfExpected = append(sliceOfExpected, expectedValue.LastChild.Data) 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) From 6a7bedcd760fa48697f4dbb283cfbaba8e920ca2 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Fri, 1 Mar 2024 15:23:18 +0000 Subject: [PATCH 05/10] fix --- e2e/utils/html.go | 2 +- e2e/utils/json.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/e2e/utils/html.go b/e2e/utils/html.go index 233ee93abd4..092e329e913 100644 --- a/e2e/utils/html.go +++ b/e2e/utils/html.go @@ -46,13 +46,13 @@ func HTMLValidation(t *testing.T, file string) { sliceOfActual := make([]string, 0, len(headerIds)) for _, header := range headerIds { expectedValue := getElementByID(expectedHTML, header) - sliceOfExpected = append(sliceOfExpected, expectedValue.LastChild.Data) 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) } + 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, diff --git a/e2e/utils/json.go b/e2e/utils/json.go index 20a16972e87..ad920d992c9 100644 --- a/e2e/utils/json.go +++ b/e2e/utils/json.go @@ -226,7 +226,12 @@ func setFields(t *testing.T, expect, actual []string, expectFileName, actualFile }) } - require.ElementsMatch(t, expectI, actualI, + 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) } From 1dcf3adb8636fc79275ed8f44134bf9b990e643d Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Fri, 1 Mar 2024 15:59:17 +0000 Subject: [PATCH 06/10] linter --- e2e/utils/json.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e/utils/json.go b/e2e/utils/json.go index ad920d992c9..3d712e6dbce 100644 --- a/e2e/utils/json.go +++ b/e2e/utils/json.go @@ -16,6 +16,8 @@ import ( "github.com/xeipuuv/gojsonschema" ) +var filekey = "file" + type logMsg struct { Level string `json:"level"` ErrorMgs string `json:"error"` @@ -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 From c2d243a92e9e1c270e8203b3d3cf67e972d40321 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Fri, 1 Mar 2024 17:00:41 +0000 Subject: [PATCH 07/10] just for test --- e2e/testcases/e2e-cli-084_helm_ignore_block.go | 2 +- e2e/testcases/e2e-cli-085_helm_disable_query.go | 2 +- e2e/testcases/e2e-cli-086_parallel_scan_default.go | 2 +- e2e/testcases/e2e-cli-087_parallel_scan_sequential.go | 2 +- e2e/testcases/e2e-cli-088_parallel_scan_6_workers.go | 2 +- e2e/testcases/e2e-cli-092_gitignore_not_exclude_project.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/e2e/testcases/e2e-cli-084_helm_ignore_block.go b/e2e/testcases/e2e-cli-084_helm_ignore_block.go index 9511bd14da4..fb9949f9bf8 100644 --- a/e2e/testcases/e2e-cli-084_helm_ignore_block.go +++ b/e2e/testcases/e2e-cli-084_helm_ignore_block.go @@ -20,7 +20,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{0}, + WantStatus: []int{10}, } Tests = append(Tests, testSample) diff --git a/e2e/testcases/e2e-cli-085_helm_disable_query.go b/e2e/testcases/e2e-cli-085_helm_disable_query.go index d120a35eeb8..ed71215ef1a 100644 --- a/e2e/testcases/e2e-cli-085_helm_disable_query.go +++ b/e2e/testcases/e2e-cli-085_helm_disable_query.go @@ -20,7 +20,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{0}, + WantStatus: []int{10}, } Tests = append(Tests, testSample) diff --git a/e2e/testcases/e2e-cli-086_parallel_scan_default.go b/e2e/testcases/e2e-cli-086_parallel_scan_default.go index f37dd8fd9b1..3fc8d1f3404 100644 --- a/e2e/testcases/e2e-cli-086_parallel_scan_default.go +++ b/e2e/testcases/e2e-cli-086_parallel_scan_default.go @@ -20,7 +20,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{50}, + WantStatus: []int{40}, } Tests = append(Tests, testSample) diff --git a/e2e/testcases/e2e-cli-087_parallel_scan_sequential.go b/e2e/testcases/e2e-cli-087_parallel_scan_sequential.go index 45d569e045b..c28a4c5e5be 100644 --- a/e2e/testcases/e2e-cli-087_parallel_scan_sequential.go +++ b/e2e/testcases/e2e-cli-087_parallel_scan_sequential.go @@ -20,7 +20,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{50}, + WantStatus: []int{40}, } Tests = append(Tests, testSample) diff --git a/e2e/testcases/e2e-cli-088_parallel_scan_6_workers.go b/e2e/testcases/e2e-cli-088_parallel_scan_6_workers.go index 7d05e3d17d7..634e83b8eed 100644 --- a/e2e/testcases/e2e-cli-088_parallel_scan_6_workers.go +++ b/e2e/testcases/e2e-cli-088_parallel_scan_6_workers.go @@ -20,7 +20,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{50}, + WantStatus: []int{40}, } Tests = append(Tests, testSample) diff --git a/e2e/testcases/e2e-cli-092_gitignore_not_exclude_project.go b/e2e/testcases/e2e-cli-092_gitignore_not_exclude_project.go index 58e826cec4c..d1ef9460089 100644 --- a/e2e/testcases/e2e-cli-092_gitignore_not_exclude_project.go +++ b/e2e/testcases/e2e-cli-092_gitignore_not_exclude_project.go @@ -19,7 +19,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{50}, + WantStatus: []int{40}, } Tests = append(Tests, testSample) From c1976f796d0adb3a115b6ba120b3478c42ae8531 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Mon, 4 Mar 2024 08:58:09 +0000 Subject: [PATCH 08/10] undo e2e --- e2e/testcases/e2e-cli-084_helm_ignore_block.go | 2 +- e2e/testcases/e2e-cli-085_helm_disable_query.go | 2 +- e2e/testcases/e2e-cli-086_parallel_scan_default.go | 2 +- e2e/testcases/e2e-cli-087_parallel_scan_sequential.go | 2 +- e2e/testcases/e2e-cli-088_parallel_scan_6_workers.go | 2 +- e2e/testcases/e2e-cli-092_gitignore_not_exclude_project.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/e2e/testcases/e2e-cli-084_helm_ignore_block.go b/e2e/testcases/e2e-cli-084_helm_ignore_block.go index fb9949f9bf8..9511bd14da4 100644 --- a/e2e/testcases/e2e-cli-084_helm_ignore_block.go +++ b/e2e/testcases/e2e-cli-084_helm_ignore_block.go @@ -20,7 +20,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{10}, + WantStatus: []int{0}, } Tests = append(Tests, testSample) diff --git a/e2e/testcases/e2e-cli-085_helm_disable_query.go b/e2e/testcases/e2e-cli-085_helm_disable_query.go index ed71215ef1a..d120a35eeb8 100644 --- a/e2e/testcases/e2e-cli-085_helm_disable_query.go +++ b/e2e/testcases/e2e-cli-085_helm_disable_query.go @@ -20,7 +20,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{10}, + WantStatus: []int{0}, } Tests = append(Tests, testSample) diff --git a/e2e/testcases/e2e-cli-086_parallel_scan_default.go b/e2e/testcases/e2e-cli-086_parallel_scan_default.go index 3fc8d1f3404..f37dd8fd9b1 100644 --- a/e2e/testcases/e2e-cli-086_parallel_scan_default.go +++ b/e2e/testcases/e2e-cli-086_parallel_scan_default.go @@ -20,7 +20,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{40}, + WantStatus: []int{50}, } Tests = append(Tests, testSample) diff --git a/e2e/testcases/e2e-cli-087_parallel_scan_sequential.go b/e2e/testcases/e2e-cli-087_parallel_scan_sequential.go index c28a4c5e5be..45d569e045b 100644 --- a/e2e/testcases/e2e-cli-087_parallel_scan_sequential.go +++ b/e2e/testcases/e2e-cli-087_parallel_scan_sequential.go @@ -20,7 +20,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{40}, + WantStatus: []int{50}, } Tests = append(Tests, testSample) diff --git a/e2e/testcases/e2e-cli-088_parallel_scan_6_workers.go b/e2e/testcases/e2e-cli-088_parallel_scan_6_workers.go index 634e83b8eed..7d05e3d17d7 100644 --- a/e2e/testcases/e2e-cli-088_parallel_scan_6_workers.go +++ b/e2e/testcases/e2e-cli-088_parallel_scan_6_workers.go @@ -20,7 +20,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{40}, + WantStatus: []int{50}, } Tests = append(Tests, testSample) diff --git a/e2e/testcases/e2e-cli-092_gitignore_not_exclude_project.go b/e2e/testcases/e2e-cli-092_gitignore_not_exclude_project.go index d1ef9460089..58e826cec4c 100644 --- a/e2e/testcases/e2e-cli-092_gitignore_not_exclude_project.go +++ b/e2e/testcases/e2e-cli-092_gitignore_not_exclude_project.go @@ -19,7 +19,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{40}, + WantStatus: []int{50}, } Tests = append(Tests, testSample) From d7af774fc583b355d0ce9d9dc846b2b8b5593ecf Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Mon, 4 Mar 2024 09:00:51 +0000 Subject: [PATCH 09/10] testing my changes, changing an expected path --- e2e/fixtures/E2E_CLI_069_RESULT.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/fixtures/E2E_CLI_069_RESULT.json b/e2e/fixtures/E2E_CLI_069_RESULT.json index a2279b47b77..f2a292f4f1e 100644 --- a/e2e/fixtures/E2E_CLI_069_RESULT.json +++ b/e2e/fixtures/E2E_CLI_069_RESULT.json @@ -22,7 +22,7 @@ "start": "2023-10-27T16:37:16.0886334+01:00", "end": "2023-10-27T16:37:16.4789259+01:00", "paths": [ - "/path/test/fixtures/experimental_test/sample", + "/path/test/fixtures/experimental_test/sample/ola", "/path/test/fixtures/experimental_test/queries" ], "queries": [ From 474e1caf24d7f01be5e32b52e8e64448b6903b52 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Mon, 4 Mar 2024 10:06:57 +0000 Subject: [PATCH 10/10] undo e2e --- e2e/fixtures/E2E_CLI_069_RESULT.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/fixtures/E2E_CLI_069_RESULT.json b/e2e/fixtures/E2E_CLI_069_RESULT.json index f2a292f4f1e..a2279b47b77 100644 --- a/e2e/fixtures/E2E_CLI_069_RESULT.json +++ b/e2e/fixtures/E2E_CLI_069_RESULT.json @@ -22,7 +22,7 @@ "start": "2023-10-27T16:37:16.0886334+01:00", "end": "2023-10-27T16:37:16.4789259+01:00", "paths": [ - "/path/test/fixtures/experimental_test/sample/ola", + "/path/test/fixtures/experimental_test/sample", "/path/test/fixtures/experimental_test/queries" ], "queries": [