diff --git a/Makefile b/Makefile
index c751446d..0fc3abf3 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,7 @@ test:
@echo -- $@ --
go test ./... -v -cover -coverprofile netpolicy.coverprofile
-test-update: # overrides/ generates tests' expected output files for relevant tests
+test-update: # overrides/ generates tests' expected output files for relevant tests
+# if the format is dot - generates also png files
@echo -- $@ --
go test ./pkg/netpol/connlist/ ./pkg/netpol/diff/ --args --update
\ No newline at end of file
diff --git a/pkg/internal/testutils/testutils.go b/pkg/internal/testutils/testutils.go
index 3740c976..dd265522 100644
--- a/pkg/internal/testutils/testutils.go
+++ b/pkg/internal/testutils/testutils.go
@@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
+ "os/exec"
"path/filepath"
"strings"
"testing"
@@ -11,6 +12,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/np-guard/netpol-analyzer/pkg/internal/output"
+ "github.com/np-guard/netpol-analyzer/pkg/logger"
)
// a flag for writing/overriding the golden result files for tests
@@ -53,6 +55,11 @@ func CheckActualVsExpectedOutputMatch(t *testing.T, testName, dirName, expectedO
if *update {
err := output.WriteToFile(actualOutput, expectedOutputFile)
require.Nil(t, err, testInfo)
+ // if format is dot - generate/ override also png graph file using graphviz program
+ if strings.HasSuffix(expectedOutputFile, dotSign+output.DOTFormat) {
+ err = generateGraphFilesIfPossible(expectedOutputFile)
+ require.Nil(t, err, testInfo)
+ }
return
}
// read expected output file
@@ -80,3 +87,28 @@ func CheckErrorContainment(t *testing.T, testInfo, expectedErrorMsg, actualErrMs
require.Contains(t, actualErrMsg, expectedErrorMsg, "err/warn message mismatch for test: %q, actual: %q, expected contains: %q",
testInfo, actualErrMsg, expectedErrorMsg)
}
+
+const (
+ // the executable we need from graphviz is "dot"
+ executableNameForGraphviz = output.DOTFormat
+ dotSign = "."
+)
+
+var graphsSuffixes = []string{"png", "svg"}
+
+// checks if "graphviz" executable exists, if yes runs a cmd to generates a png graph file from the dot output
+func generateGraphFilesIfPossible(dotFilePath string) error {
+ // check if graphviz is installed to continue
+ if _, err := exec.LookPath(executableNameForGraphviz); err != nil {
+ logger.NewDefaultLogger().Warnf("dot executable of graphviz was not found. Output Graphs will not be generated")
+ return nil
+ }
+ for _, graphSuffix := range graphsSuffixes {
+ graphFilePath := dotFilePath + dotSign + graphSuffix
+ cmd := exec.Command("dot", dotFilePath, "-T"+graphSuffix, "-o", graphFilePath) //nolint:gosec // nosec
+ if err := cmd.Run(); err != nil {
+ return err
+ }
+ }
+ return nil
+}
diff --git a/tests/acs-security-demos-added-workloads/diff_output_from_acs-security-demos.dot.svg b/tests/acs-security-demos-added-workloads/diff_output_from_acs-security-demos.dot.svg
new file mode 100644
index 00000000..053820a7
--- /dev/null
+++ b/tests/acs-security-demos-added-workloads/diff_output_from_acs-security-demos.dot.svg
@@ -0,0 +1,282 @@
+
+
+
+
+
diff --git a/tests/acs-security-demos-new/diff_output_from_acs-security-demos.dot.png b/tests/acs-security-demos-new/diff_output_from_acs-security-demos.dot.png
index c31b40cd..9625d6dc 100644
Binary files a/tests/acs-security-demos-new/diff_output_from_acs-security-demos.dot.png and b/tests/acs-security-demos-new/diff_output_from_acs-security-demos.dot.png differ
diff --git a/tests/acs-security-demos-new/diff_output_from_acs-security-demos.dot.svg b/tests/acs-security-demos-new/diff_output_from_acs-security-demos.dot.svg
new file mode 100644
index 00000000..0b38d419
--- /dev/null
+++ b/tests/acs-security-demos-new/diff_output_from_acs-security-demos.dot.svg
@@ -0,0 +1,311 @@
+
+
+
+
+
diff --git a/tests/acs-security-demos/connlist_output.dot.svg b/tests/acs-security-demos/connlist_output.dot.svg
new file mode 100644
index 00000000..e7689fa9
--- /dev/null
+++ b/tests/acs-security-demos/connlist_output.dot.svg
@@ -0,0 +1,182 @@
+
+
+
+
+
diff --git a/tests/acs_security_frontend_demos/connlist_output.dot.png b/tests/acs_security_frontend_demos/connlist_output.dot.png
new file mode 100644
index 00000000..bcaf83aa
Binary files /dev/null and b/tests/acs_security_frontend_demos/connlist_output.dot.png differ
diff --git a/tests/acs_security_frontend_demos/connlist_output.dot.svg b/tests/acs_security_frontend_demos/connlist_output.dot.svg
new file mode 100644
index 00000000..9aeb5a7f
--- /dev/null
+++ b/tests/acs_security_frontend_demos/connlist_output.dot.svg
@@ -0,0 +1,12 @@
+
+
+
+
+
diff --git a/tests/demo_app_with_routes_and_ingress/connlist_output.dot.svg b/tests/demo_app_with_routes_and_ingress/connlist_output.dot.svg
new file mode 100644
index 00000000..fbdb8a6d
--- /dev/null
+++ b/tests/demo_app_with_routes_and_ingress/connlist_output.dot.svg
@@ -0,0 +1,147 @@
+
+
+
+
+
diff --git a/tests/k8s_ingress_test/connlist_output.dot.svg b/tests/k8s_ingress_test/connlist_output.dot.svg
new file mode 100644
index 00000000..11502c47
--- /dev/null
+++ b/tests/k8s_ingress_test/connlist_output.dot.svg
@@ -0,0 +1,361 @@
+
+
+
+
+
diff --git a/tests/k8s_ingress_test_new/diff_output_from_k8s_ingress_test.dot.png b/tests/k8s_ingress_test_new/diff_output_from_k8s_ingress_test.dot.png
index 716d472c..bfc62b63 100644
Binary files a/tests/k8s_ingress_test_new/diff_output_from_k8s_ingress_test.dot.png and b/tests/k8s_ingress_test_new/diff_output_from_k8s_ingress_test.dot.png differ
diff --git a/tests/k8s_ingress_test_new/diff_output_from_k8s_ingress_test.dot.svg b/tests/k8s_ingress_test_new/diff_output_from_k8s_ingress_test.dot.svg
new file mode 100644
index 00000000..ce43d1e5
--- /dev/null
+++ b/tests/k8s_ingress_test_new/diff_output_from_k8s_ingress_test.dot.svg
@@ -0,0 +1,456 @@
+
+
+
+
+
diff --git a/tests/multiple_ingress_objects_with_different_ports/connlist_output.dot.svg b/tests/multiple_ingress_objects_with_different_ports/connlist_output.dot.svg
new file mode 100644
index 00000000..233c729b
--- /dev/null
+++ b/tests/multiple_ingress_objects_with_different_ports/connlist_output.dot.svg
@@ -0,0 +1,51 @@
+
+
+
+
+
diff --git a/tests/multiple_ingress_objects_with_different_ports_new/diff_output_from_multiple_ingress_objects_with_different_ports.dot.png b/tests/multiple_ingress_objects_with_different_ports_new/diff_output_from_multiple_ingress_objects_with_different_ports.dot.png
index 8c33bcd5..1f09f9d0 100644
Binary files a/tests/multiple_ingress_objects_with_different_ports_new/diff_output_from_multiple_ingress_objects_with_different_ports.dot.png and b/tests/multiple_ingress_objects_with_different_ports_new/diff_output_from_multiple_ingress_objects_with_different_ports.dot.png differ
diff --git a/tests/multiple_ingress_objects_with_different_ports_new/diff_output_from_multiple_ingress_objects_with_different_ports.dot.svg b/tests/multiple_ingress_objects_with_different_ports_new/diff_output_from_multiple_ingress_objects_with_different_ports.dot.svg
new file mode 100644
index 00000000..2d85b7c2
--- /dev/null
+++ b/tests/multiple_ingress_objects_with_different_ports_new/diff_output_from_multiple_ingress_objects_with_different_ports.dot.svg
@@ -0,0 +1,112 @@
+
+
+
+
+
diff --git a/tests/netpol-diff-example-minimal/diff_output_from_netpol-analysis-example-minimal.dot.png b/tests/netpol-diff-example-minimal/diff_output_from_netpol-analysis-example-minimal.dot.png
index b4070c57..4c987ee6 100644
Binary files a/tests/netpol-diff-example-minimal/diff_output_from_netpol-analysis-example-minimal.dot.png and b/tests/netpol-diff-example-minimal/diff_output_from_netpol-analysis-example-minimal.dot.png differ
diff --git a/tests/netpol-diff-example-minimal/diff_output_from_netpol-analysis-example-minimal.dot.svg b/tests/netpol-diff-example-minimal/diff_output_from_netpol-analysis-example-minimal.dot.svg
new file mode 100644
index 00000000..fb189d83
--- /dev/null
+++ b/tests/netpol-diff-example-minimal/diff_output_from_netpol-analysis-example-minimal.dot.svg
@@ -0,0 +1,119 @@
+
+
+
+
+
diff --git a/tests/one_ingress_multiple_ports/connlist_output.dot.svg b/tests/one_ingress_multiple_ports/connlist_output.dot.svg
new file mode 100644
index 00000000..acfc28cb
--- /dev/null
+++ b/tests/one_ingress_multiple_ports/connlist_output.dot.svg
@@ -0,0 +1,51 @@
+
+
+
+
+
diff --git a/tests/one_ingress_multiple_services/connlist_output.dot.svg b/tests/one_ingress_multiple_services/connlist_output.dot.svg
new file mode 100644
index 00000000..acfc28cb
--- /dev/null
+++ b/tests/one_ingress_multiple_services/connlist_output.dot.svg
@@ -0,0 +1,51 @@
+
+
+
+
+
diff --git a/tests/onlineboutique_workloads/connlist_output.dot.svg b/tests/onlineboutique_workloads/connlist_output.dot.svg
new file mode 100644
index 00000000..df5ca046
--- /dev/null
+++ b/tests/onlineboutique_workloads/connlist_output.dot.svg
@@ -0,0 +1,209 @@
+
+
+
+
+
diff --git a/tests/onlineboutique_workloads_changed_netpols/TsetOutputWithArgNamesOption.dot.png b/tests/onlineboutique_workloads_changed_netpols/TsetOutputWithArgNamesOption.dot.png
new file mode 100644
index 00000000..c1050ce4
Binary files /dev/null and b/tests/onlineboutique_workloads_changed_netpols/TsetOutputWithArgNamesOption.dot.png differ
diff --git a/tests/onlineboutique_workloads_changed_netpols/TsetOutputWithArgNamesOption.dot.svg b/tests/onlineboutique_workloads_changed_netpols/TsetOutputWithArgNamesOption.dot.svg
new file mode 100644
index 00000000..44ff62d1
--- /dev/null
+++ b/tests/onlineboutique_workloads_changed_netpols/TsetOutputWithArgNamesOption.dot.svg
@@ -0,0 +1,303 @@
+
+
+
+
+
diff --git a/tests/onlineboutique_workloads_changed_netpols/diff_output_from_onlineboutique_workloads.dot.png b/tests/onlineboutique_workloads_changed_netpols/diff_output_from_onlineboutique_workloads.dot.png
index c1050ce4..5e54ba6c 100644
Binary files a/tests/onlineboutique_workloads_changed_netpols/diff_output_from_onlineboutique_workloads.dot.png and b/tests/onlineboutique_workloads_changed_netpols/diff_output_from_onlineboutique_workloads.dot.png differ
diff --git a/tests/onlineboutique_workloads_changed_netpols/diff_output_from_onlineboutique_workloads.dot.svg b/tests/onlineboutique_workloads_changed_netpols/diff_output_from_onlineboutique_workloads.dot.svg
new file mode 100644
index 00000000..dfb7a014
--- /dev/null
+++ b/tests/onlineboutique_workloads_changed_netpols/diff_output_from_onlineboutique_workloads.dot.svg
@@ -0,0 +1,303 @@
+
+
+
+
+
diff --git a/tests/onlineboutique_workloads_changed_netpols_and_workloads/diff_output_from_onlineboutique_workloads.dot.png b/tests/onlineboutique_workloads_changed_netpols_and_workloads/diff_output_from_onlineboutique_workloads.dot.png
index 0d6c2335..57685b12 100644
Binary files a/tests/onlineboutique_workloads_changed_netpols_and_workloads/diff_output_from_onlineboutique_workloads.dot.png and b/tests/onlineboutique_workloads_changed_netpols_and_workloads/diff_output_from_onlineboutique_workloads.dot.png differ
diff --git a/tests/onlineboutique_workloads_changed_netpols_and_workloads/diff_output_from_onlineboutique_workloads.dot.svg b/tests/onlineboutique_workloads_changed_netpols_and_workloads/diff_output_from_onlineboutique_workloads.dot.svg
new file mode 100644
index 00000000..6af4ecea
--- /dev/null
+++ b/tests/onlineboutique_workloads_changed_netpols_and_workloads/diff_output_from_onlineboutique_workloads.dot.svg
@@ -0,0 +1,323 @@
+
+
+
+
+
diff --git a/tests/onlineboutique_workloads_changed_workloads/diff_output_from_onlineboutique_workloads.dot.svg b/tests/onlineboutique_workloads_changed_workloads/diff_output_from_onlineboutique_workloads.dot.svg
new file mode 100644
index 00000000..8e361f53
--- /dev/null
+++ b/tests/onlineboutique_workloads_changed_workloads/diff_output_from_onlineboutique_workloads.dot.svg
@@ -0,0 +1,304 @@
+
+
+
+
+