mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Minimize PR 22 (#26)
* specific functions added to eval different rego components Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * allow multiple inputs and results Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * prepare_for_eval is necessary to be called Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * test with the suggested code examples and clean scopes Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * try to refactor first steps of evaluations Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * improve coverage and fix clean state internal evaluation Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * add getters and setters and fix clean function Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * Tests are single input by default. Multi input specified via "many!" marker. Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> --------- Signed-off-by: eric-therond <eric.therond.fr@gmail.com> Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> Co-authored-by: eric-therond <eric.therond.fr@gmail.com>
This commit is contained in:
committed by
GitHub
parent
2ba718ba72
commit
2436467fbd
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::interpreter::*;
|
||||
use anyhow::Result;
|
||||
|
||||
#[test]
|
||||
fn basic() -> Result<()> {
|
||||
let rego = r#"
|
||||
package test
|
||||
|
||||
x[a] {
|
||||
a = y
|
||||
}
|
||||
|
||||
y[a] {
|
||||
a = input.x + 5
|
||||
}
|
||||
"#;
|
||||
|
||||
let input = ValueOrVec::Many(vec![
|
||||
Value::from_json_str(r#"{"x": 1}"#)?,
|
||||
Value::from_json_str(r#"{"x": 6}"#)?,
|
||||
]);
|
||||
|
||||
let expected = vec![
|
||||
Value::from_json_str(
|
||||
r#" {
|
||||
"y": {"set!": [6]},
|
||||
"x": {"set!": [{"set!":[6]}]}
|
||||
}"#,
|
||||
)?,
|
||||
Value::from_json_str(
|
||||
r#" {
|
||||
"y": {"set!": [11]},
|
||||
"x": {"set!": [{"set!":[11]}]}
|
||||
}"#,
|
||||
)?,
|
||||
];
|
||||
|
||||
assert_match(
|
||||
eval_file_first_rule(&[rego.to_owned()], None, Some(input), "data.test", false)?,
|
||||
expected,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: input-multiple-1
|
||||
data: {}
|
||||
input:
|
||||
many!:
|
||||
- { x: 1 }
|
||||
- { x: 5 }
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x[a] {
|
||||
a = y
|
||||
}
|
||||
|
||||
y[a] {
|
||||
a = input.x + 5
|
||||
}
|
||||
|
||||
query: data.test
|
||||
want_result:
|
||||
many!:
|
||||
- y:
|
||||
set!: [6]
|
||||
x:
|
||||
set!: [ set!: [6] ]
|
||||
- y:
|
||||
set!: [10]
|
||||
x:
|
||||
set!: [ set!: [10] ]
|
||||
@@ -0,0 +1,27 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: input-basic-1
|
||||
data: {}
|
||||
input: {
|
||||
x: 1
|
||||
}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x[a] {
|
||||
a = y
|
||||
}
|
||||
|
||||
y[a] {
|
||||
a = input.x + 5
|
||||
}
|
||||
|
||||
query: data.test
|
||||
want_result:
|
||||
y:
|
||||
set!: [6]
|
||||
x:
|
||||
set!: [ set!: [6] ]
|
||||
Reference in New Issue
Block a user