diff --git a/core/pkg/fixhandler/fixhandler_test.go b/core/pkg/fixhandler/fixhandler_test.go index 4b263ef1..44a26b23 100644 --- a/core/pkg/fixhandler/fixhandler_test.go +++ b/core/pkg/fixhandler/fixhandler_test.go @@ -40,22 +40,22 @@ func getTestCases() []indentationTestCase { indentationTestCases := []indentationTestCase{ // Insertion Scenarios { - "inserts/tc-01-00-input.yaml", + "inserts/tc-01-00-input-mapping-insert-mapping.yaml", "select(di==0).spec.containers[0].securityContext.allowPrivilegeEscalation |= false", "inserts/tc-01-01-expected.yaml", }, { - "inserts/tc-02-00-input.yaml", + "inserts/tc-02-00-input-mapping-insert-mapping-with-list.yaml", "select(di==0).spec.containers[0].securityContext.capabilities.drop += [\"NET_RAW\"]", "inserts/tc-02-01-expected.yaml", }, { - "inserts/tc-03-00-input.yaml", + "inserts/tc-03-00-input-list-append-scalar.yaml", "select(di==0).spec.containers[0].securityContext.capabilities.drop += [\"SYS_ADM\"]", "inserts/tc-03-01-expected.yaml", }, { - "inserts/tc-04-00-input.yaml", + "inserts/tc-04-00-input-multiple-inserts.yaml", `select(di==0).spec.template.spec.securityContext.allowPrivilegeEscalation |= false | select(di==0).spec.template.spec.containers[0].securityContext.capabilities.drop += ["NET_RAW"] | @@ -66,23 +66,38 @@ func getTestCases() []indentationTestCase { "inserts/tc-04-01-expected.yaml", }, { - "inserts/tc-05-00-input.yaml", + "inserts/tc-05-00-input-comment-blank-line-single-insert.yaml", "select(di==0).spec.containers[0].securityContext.allowPrivilegeEscalation |= false", "inserts/tc-05-01-expected.yaml", }, { - "inserts/tc-06-00-input.yaml", + "inserts/tc-06-00-input-list-append-scalar-oneline.yaml", "select(di==0).spec.containers[0].securityContext.capabilities.drop += [\"SYS_ADM\"]", "inserts/tc-06-01-expected.yaml", }, { - "inserts/tc-07-00-input.yaml", + "inserts/tc-07-00-input-multiple-documents.yaml", `select(di==0).spec.containers[0].securityContext.allowPrivilegeEscalation |= false | select(di==1).spec.containers[0].securityContext.allowPrivilegeEscalation |= false`, "inserts/tc-07-01-expected.yaml", }, + { + "inserts/tc-08-00-input-mapping-insert-mapping-indented.yaml", + "select(di==0).spec.containers[0].securityContext.capabilities.drop += [\"NET_RAW\"]", + "inserts/tc-08-01-expected.yaml", + }, + { + "inserts/tc-09-00-input-list-insert-new-mapping-indented.yaml", + `select(di==0).spec.containers += {"name": "redis", "image": "redis"}`, + "inserts/tc-09-01-expected.yaml", + }, + { + "inserts/tc-10-00-input-list-insert-new-mapping.yaml", + `select(di==0).spec.containers += {"name": "redis", "image": "redis"}`, + "inserts/tc-10-01-expected.yaml", + }, // Removal Scenarios { diff --git a/core/pkg/fixhandler/testdata/inserts/tc-01-00-input.yaml b/core/pkg/fixhandler/testdata/inserts/tc-01-00-input-mapping-insert-mapping.yaml similarity index 100% rename from core/pkg/fixhandler/testdata/inserts/tc-01-00-input.yaml rename to core/pkg/fixhandler/testdata/inserts/tc-01-00-input-mapping-insert-mapping.yaml diff --git a/core/pkg/fixhandler/testdata/inserts/tc-02-00-input.yaml b/core/pkg/fixhandler/testdata/inserts/tc-02-00-input-mapping-insert-mapping-with-list.yaml similarity index 100% rename from core/pkg/fixhandler/testdata/inserts/tc-02-00-input.yaml rename to core/pkg/fixhandler/testdata/inserts/tc-02-00-input-mapping-insert-mapping-with-list.yaml diff --git a/core/pkg/fixhandler/testdata/inserts/tc-03-00-input.yaml b/core/pkg/fixhandler/testdata/inserts/tc-03-00-input-list-append-scalar.yaml similarity index 100% rename from core/pkg/fixhandler/testdata/inserts/tc-03-00-input.yaml rename to core/pkg/fixhandler/testdata/inserts/tc-03-00-input-list-append-scalar.yaml diff --git a/core/pkg/fixhandler/testdata/inserts/tc-04-00-input.yaml b/core/pkg/fixhandler/testdata/inserts/tc-04-00-input-multiple-inserts.yaml similarity index 100% rename from core/pkg/fixhandler/testdata/inserts/tc-04-00-input.yaml rename to core/pkg/fixhandler/testdata/inserts/tc-04-00-input-multiple-inserts.yaml diff --git a/core/pkg/fixhandler/testdata/inserts/tc-05-00-input.yaml b/core/pkg/fixhandler/testdata/inserts/tc-05-00-input-comment-blank-line-single-insert.yaml similarity index 100% rename from core/pkg/fixhandler/testdata/inserts/tc-05-00-input.yaml rename to core/pkg/fixhandler/testdata/inserts/tc-05-00-input-comment-blank-line-single-insert.yaml diff --git a/core/pkg/fixhandler/testdata/inserts/tc-06-00-input.yaml b/core/pkg/fixhandler/testdata/inserts/tc-06-00-input-list-append-scalar-oneline.yaml similarity index 100% rename from core/pkg/fixhandler/testdata/inserts/tc-06-00-input.yaml rename to core/pkg/fixhandler/testdata/inserts/tc-06-00-input-list-append-scalar-oneline.yaml diff --git a/core/pkg/fixhandler/testdata/inserts/tc-07-00-input.yaml b/core/pkg/fixhandler/testdata/inserts/tc-07-00-input-multiple-documents.yaml similarity index 100% rename from core/pkg/fixhandler/testdata/inserts/tc-07-00-input.yaml rename to core/pkg/fixhandler/testdata/inserts/tc-07-00-input-multiple-documents.yaml diff --git a/core/pkg/fixhandler/testdata/inserts/tc-08-00-input-mapping-insert-mapping-indented.yaml b/core/pkg/fixhandler/testdata/inserts/tc-08-00-input-mapping-insert-mapping-indented.yaml new file mode 100644 index 00000000..ac27db64 --- /dev/null +++ b/core/pkg/fixhandler/testdata/inserts/tc-08-00-input-mapping-insert-mapping-indented.yaml @@ -0,0 +1,11 @@ +# Fix to Apply: +# select(di==0).spec.containers[0].securityContext.capabilities.drop += ["NET_RAW"] + +apiVersion: v1 +kind: Pod +metadata: + name: indented-parent-list-insert-list-value +spec: + containers: + - name: nginx_container + image: nginx diff --git a/core/pkg/fixhandler/testdata/inserts/tc-08-01-expected.yaml b/core/pkg/fixhandler/testdata/inserts/tc-08-01-expected.yaml new file mode 100644 index 00000000..46a3acbe --- /dev/null +++ b/core/pkg/fixhandler/testdata/inserts/tc-08-01-expected.yaml @@ -0,0 +1,15 @@ +# Fix to Apply: +# select(di==0).spec.containers[0].securityContext.capabilities.drop += ["NET_RAW"] + +apiVersion: v1 +kind: Pod +metadata: + name: indented-parent-list-insert-list-value +spec: + containers: + - name: nginx_container + image: nginx + securityContext: + capabilities: + drop: + - NET_RAW diff --git a/core/pkg/fixhandler/testdata/inserts/tc-09-00-input-list-insert-new-mapping-indented.yaml b/core/pkg/fixhandler/testdata/inserts/tc-09-00-input-list-insert-new-mapping-indented.yaml new file mode 100644 index 00000000..416c0c1a --- /dev/null +++ b/core/pkg/fixhandler/testdata/inserts/tc-09-00-input-list-insert-new-mapping-indented.yaml @@ -0,0 +1,11 @@ +# Fix to Apply: +# select(di==0).spec.containers += {"name": "redis", "image": "redis"} + +apiVersion: v1 +kind: Pod +metadata: + name: indented-parent-list-insert-list-value +spec: + containers: + - name: nginx_container + image: nginx diff --git a/core/pkg/fixhandler/testdata/inserts/tc-09-01-expected.yaml b/core/pkg/fixhandler/testdata/inserts/tc-09-01-expected.yaml new file mode 100644 index 00000000..61ce65f7 --- /dev/null +++ b/core/pkg/fixhandler/testdata/inserts/tc-09-01-expected.yaml @@ -0,0 +1,13 @@ +# Fix to Apply: +# select(di==0).spec.containers += {"name": "redis", "image": "redis"} + +apiVersion: v1 +kind: Pod +metadata: + name: indented-parent-list-insert-list-value +spec: + containers: + - name: nginx_container + image: nginx + - name: redis + image: redis diff --git a/core/pkg/fixhandler/testdata/inserts/tc-10-00-input-list-insert-new-mapping.yaml b/core/pkg/fixhandler/testdata/inserts/tc-10-00-input-list-insert-new-mapping.yaml new file mode 100644 index 00000000..827cad1d --- /dev/null +++ b/core/pkg/fixhandler/testdata/inserts/tc-10-00-input-list-insert-new-mapping.yaml @@ -0,0 +1,11 @@ +# Fix to Apply: +# select(di==0).spec.containers += {"name": "redis", "image": "redis"} + +apiVersion: v1 +kind: Pod +metadata: + name: indented-list-insert-new-object +spec: + containers: + - name: nginx_container + image: nginx diff --git a/core/pkg/fixhandler/testdata/inserts/tc-10-01-expected.yaml b/core/pkg/fixhandler/testdata/inserts/tc-10-01-expected.yaml new file mode 100644 index 00000000..a46f6b75 --- /dev/null +++ b/core/pkg/fixhandler/testdata/inserts/tc-10-01-expected.yaml @@ -0,0 +1,13 @@ +# Fix to Apply: +# select(di==0).spec.containers += {"name": "redis", "image": "redis"} + +apiVersion: v1 +kind: Pod +metadata: + name: indented-list-insert-new-object +spec: + containers: + - name: nginx_container + image: nginx + - name: redis + image: redis