-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: rework opa mutation rules to produce actual arrays
- Loading branch information
Showing
6 changed files
with
194 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
package hello_world_meta | ||
|
||
import rego.v1 | ||
|
||
patch[operation] { | ||
add_meta_ops contains operation if { | ||
object.get(input, "Meta", null) == null | ||
|
||
not input.Meta | ||
operation := { | ||
"op": "add", | ||
"path": "/Meta", | ||
"value": {} | ||
} | ||
operation := { | ||
"op": "add", | ||
"path": "/Meta", | ||
"value": {}, | ||
} | ||
} | ||
patch[operation] { | ||
|
||
is_null(input.Meta) | ||
operation := { | ||
"op": "add", | ||
"path": "/Meta", | ||
"value": {} | ||
} | ||
} | ||
patch[operation] { | ||
add_hello_to_meta_ops contains operation if { | ||
object.get(input, ["Meta", "hello"], null) == null | ||
|
||
not input.Meta.hello | ||
operation := { | ||
"op": "add", | ||
"path": "/Meta/hello", | ||
"value": "world" | ||
} | ||
operation := { | ||
"op": "add", | ||
"path": "/Meta/hello", | ||
"value": "world", | ||
} | ||
} | ||
|
||
patch := [ operation | | ||
some ops in [add_meta_ops, add_hello_to_meta_ops] | ||
operation := ops[_] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,64 @@ | ||
package hello_world_meta_test | ||
|
||
import data.hello_world_meta.patch | ||
import data.hello_world_meta | ||
|
||
import future.keywords | ||
import rego.v1 | ||
|
||
test_hello_world if { | ||
e := patch with input as { | ||
e := hello_world_meta.patch with input as { | ||
"ID": "my-job", | ||
"Meta": {}, | ||
} | ||
e[{ | ||
"op": "add", | ||
"path": "/Meta/hello", | ||
"value": "world" | ||
}] | ||
|
||
count(e) == 1 | ||
e == [{ | ||
"op": "add", | ||
"path": "/Meta/hello", | ||
"value": "world", | ||
}] | ||
} | ||
|
||
test_hello_world_add_meta if { | ||
e := patch with input as { | ||
"ID": "my-job" | ||
} | ||
count(e) == 2 | ||
trace(sprintf("patch: %v", [e])) | ||
e := hello_world_meta.patch with input as {"ID": "my-job"} | ||
|
||
e == { | ||
{ | ||
"op": "add", | ||
"path": "/Meta", | ||
"value": {} | ||
}, | ||
{ | ||
"op": "add", | ||
"path": "/Meta/hello", | ||
"value": "world" | ||
} | ||
} | ||
e == [ | ||
{ | ||
"op": "add", | ||
"path": "/Meta", | ||
"value": {}, | ||
}, | ||
{ | ||
"op": "add", | ||
"path": "/Meta/hello", | ||
"value": "world", | ||
}, | ||
] | ||
} | ||
|
||
test_hello_world_add_meta_if_meta_null if { | ||
e := patch with input as { | ||
e := hello_world_meta.patch with input as { | ||
"ID": "my-job", | ||
"Meta": null | ||
"Meta": null, | ||
} | ||
count(e) == 2 | ||
trace(sprintf("patch: %v", [e])) | ||
count(e) == 2 | ||
|
||
e == { | ||
{ | ||
"op": "add", | ||
"path": "/Meta", | ||
"value": {} | ||
}, | ||
{ | ||
"op": "add", | ||
"path": "/Meta/hello", | ||
"value": "world" | ||
} | ||
} | ||
e == [ | ||
{ | ||
"op": "add", | ||
"path": "/Meta", | ||
"value": {}, | ||
}, | ||
{ | ||
"op": "add", | ||
"path": "/Meta/hello", | ||
"value": "world", | ||
}, | ||
] | ||
} | ||
|
||
test_hello_world_no_code_if_exists if { | ||
e := patch with input as { | ||
e := hello_world_meta.patch with input as { | ||
"ID": "my-job", | ||
"Meta": {"hello": "world"} | ||
"Meta": {"hello": "world"}, | ||
} | ||
count(e) == 0 | ||
|
||
count(e) == 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.