mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
rego-v1: Future-proofing topdown pkg tests to be 1.0 compatible (#7014)
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
---
|
||||
cases:
|
||||
- data:
|
||||
ok: "package foo.bar\n\n\t\timport data.a\n\n\t\tp { a = true }"
|
||||
ok: |-
|
||||
package foo.bar
|
||||
|
||||
import rego.v1
|
||||
import data.a
|
||||
|
||||
p if { a = true }
|
||||
modules:
|
||||
- |
|
||||
package generated
|
||||
|
||||
@@ -15,8 +15,9 @@ cases:
|
||||
ok: |-
|
||||
package foo.bar
|
||||
|
||||
import data.a
|
||||
import rego.v1
|
||||
import data.a
|
||||
|
||||
p { a = true }
|
||||
p if { a = true }
|
||||
want_result:
|
||||
- x: foo
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestNetCIDRExpandCancellation(t *testing.T) {
|
||||
`
|
||||
package test
|
||||
|
||||
p { net.cidr_expand("1.0.0.0/1") } # generating 2**31 hosts will take a while...
|
||||
p if { net.cidr_expand("1.0.0.0/1") } # generating 2**31 hosts will take a while...
|
||||
`,
|
||||
})
|
||||
|
||||
|
||||
+135
-140
@@ -261,7 +261,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
note: "different args",
|
||||
module: `package p
|
||||
f(0) = 1
|
||||
f(x) = 12 { x > 0 }`,
|
||||
f(x) = 12 if { x > 0 }`,
|
||||
query: `data.p.f(0); data.p.f(1)`,
|
||||
hit: 0,
|
||||
miss: 2,
|
||||
@@ -270,7 +270,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
note: "same args",
|
||||
module: `package p
|
||||
f(0) = 1
|
||||
f(x) = 12 { x > 0 }`,
|
||||
f(x) = 12 if { x > 0 }`,
|
||||
query: `data.p.f(1); data.p.f(1)`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -279,7 +279,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
note: "captured output",
|
||||
module: `package p
|
||||
f(0) = 1
|
||||
f(x) = 12 { x > 0 }`,
|
||||
f(x) = 12 if { x > 0 }`,
|
||||
query: `data.p.f(0); data.p.f(0, x)`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -288,8 +288,8 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "captured output, bool(false) result",
|
||||
module: `package p
|
||||
g(x) = true { x > 0 }
|
||||
g(x) = false { x <= 0 }`,
|
||||
g(x) = true if { x > 0 }
|
||||
g(x) = false if { x <= 0 }`,
|
||||
query: `data.p.g(-1, x); data.p.g(-1, y)`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -299,8 +299,8 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
note: "same args, iteration case",
|
||||
module: `package p
|
||||
f(0) = 1
|
||||
f(x) = 12 { x > 0 }
|
||||
q = y {
|
||||
f(x) = 12 if { x > 0 }
|
||||
q = y if {
|
||||
x := f(1)
|
||||
y := f(1)
|
||||
x == y
|
||||
@@ -313,7 +313,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "cache invalidation",
|
||||
module: `package p
|
||||
f(x) = y { x+input = y }`,
|
||||
f(x) = y if { x+input = y }`,
|
||||
query: `data.p.f(1, z) with input as 7; data.p.f(1, z2) with input as 8`,
|
||||
hit: 0,
|
||||
miss: 2,
|
||||
@@ -321,8 +321,8 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple",
|
||||
module: `package p
|
||||
s["foo"] = true { true }
|
||||
s["bar"] = true { true }`,
|
||||
s["foo"] = true if { true }
|
||||
s["bar"] = true if { true }`,
|
||||
query: `data.p.s["foo"]; data.p.s["foo"]`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -330,8 +330,8 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: query into object value",
|
||||
module: `package p
|
||||
s["foo"] = { "x": 42, "y": 43 } { true }
|
||||
s["bar"] = { "x": 42, "y": 43 } { true }`,
|
||||
s["foo"] = { "x": 42, "y": 43 } if { true }
|
||||
s["bar"] = { "x": 42, "y": 43 } if { true }`,
|
||||
query: `data.p.s["foo"].x = x; data.p.s["foo"].y`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -340,7 +340,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref",
|
||||
module: `package p
|
||||
s.t[u].v = true { x = ["foo", "bar"]; u = x[_] }`,
|
||||
s.t[u].v = true if { x = ["foo", "bar"]; u = x[_] }`,
|
||||
query: `data.p.s.t["foo"].v = x; data.p.s.t["foo"].v`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -349,7 +349,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref, multiple vars",
|
||||
module: `package p
|
||||
s.t[u].v[w] = true { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[_] }`,
|
||||
s.t[u].v[w] = true if { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[_] }`,
|
||||
query: `data.p.s.t = x; data.p.s.t`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -371,7 +371,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref, multiple vars (2)",
|
||||
module: `package p
|
||||
s.t[u].v[w] = true { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[_] }`,
|
||||
s.t[u].v[w] = true if { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[_] }`,
|
||||
query: `data.p.s.t.foo = x; data.p.s.t["foo"]`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -385,7 +385,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref, multiple vars (3)",
|
||||
module: `package p
|
||||
s.t[u].v[w] = true { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[_] }`,
|
||||
s.t[u].v[w] = true if { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[_] }`,
|
||||
query: `data.p.s.t.foo.v = x; data.p.s.t["foo"].v`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -397,7 +397,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref, multiple vars (4)",
|
||||
module: `package p
|
||||
s.t[u].v[w] = true { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[_] }`,
|
||||
s.t[u].v[w] = true if { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[_] }`,
|
||||
query: `data.p.s.t.foo.v.re = x; data.p.s.t["foo"].v["re"]`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -406,7 +406,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref, miss",
|
||||
module: `package p
|
||||
s.t[u].v[w] = true { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[_] }`,
|
||||
s.t[u].v[w] = true if { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[_] }`,
|
||||
query: `data.p.s.t.foo.v.re = x; data.p.s.t.foo.v.do`,
|
||||
hit: 0,
|
||||
miss: 2,
|
||||
@@ -415,7 +415,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref, miss (2)",
|
||||
module: `package p
|
||||
s.t[u].v[w] = i { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
s.t[u].v[w] = i if { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
query: `data.p.s.t.foo.v.re = x; data.p.s.t.foo.v.do; data.p.s.t.foo.v.re`,
|
||||
hit: 1,
|
||||
miss: 2,
|
||||
@@ -424,7 +424,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref, miss (3)",
|
||||
module: `package p
|
||||
s.t[u].v[w] = i { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
s.t[u].v[w] = i if { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
query: `data.p.s.t.foo.v.re = x; data.p.s.t.foo.v.do; data.p.s.t.bar.v.re`,
|
||||
hit: 0,
|
||||
miss: 3,
|
||||
@@ -433,7 +433,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref, miss (3)",
|
||||
module: `package p
|
||||
s.t[u].v[w] = i { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
s.t[u].v[w] = i if { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
query: `data.p.s.t.foo.v.re = x; data.p.s.t.foo.v.do; data.p.s.t.bar.v.re; data.p.s.t.foo.v.do`,
|
||||
hit: 1,
|
||||
miss: 3,
|
||||
@@ -442,7 +442,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref, miss (4)",
|
||||
module: `package p
|
||||
s.t[u].v[w] = i { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
s.t[u].v[w] = i if { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
query: `data.p.s.t.foo = x; data.p.s.t.foo.v.do`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -456,7 +456,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref, miss (5)",
|
||||
module: `package p
|
||||
s.t[u].v[w] = i { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
s.t[u].v[w] = i if { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
query: `data.p.s.t.foo; data.p.s.t.foo.v.do = x`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -465,7 +465,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, general ref, miss (6)",
|
||||
module: `package p
|
||||
s.t[u].v[w] = i { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
s.t[u].v[w] = i if { x = ["foo", "bar"]; u = x[_]; y = ["do", "re"]; w = y[i] }`,
|
||||
query: `data.p.s.t.foo.v.do = x; data.p.s.t.foo`,
|
||||
hit: 0, // Note: Could we be smart in query term eval order to gain an extra hit here?
|
||||
miss: 2,
|
||||
@@ -474,8 +474,8 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object: simple, query into value",
|
||||
module: `package p
|
||||
s["foo"].t = { "x": 42, "y": 43 } { true }
|
||||
s["bar"].t = { "x": 42, "y": 43 } { true }`,
|
||||
s["foo"].t = { "x": 42, "y": 43 } if { true }
|
||||
s["bar"].t = { "x": 42, "y": 43 } if { true }`,
|
||||
query: `data.p.s["foo"].t.x = x; data.p.s["foo"].t.x`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -484,8 +484,8 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial set: simple",
|
||||
module: `package p
|
||||
s["foo"] { true }
|
||||
s["bar"] { true }`,
|
||||
s contains "foo" if { true }
|
||||
s contains "bar" if { true }`,
|
||||
query: `data.p.s["foo"]; data.p.s["foo"]`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -493,7 +493,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial set: object",
|
||||
module: `package p
|
||||
s[z] { z := {"foo": "bar"} }`,
|
||||
s contains z if { z := {"foo": "bar"} }`,
|
||||
query: `x = {"foo": "bar"}; data.p.s[x]; data.p.s[x]`,
|
||||
hit: 1,
|
||||
miss: 1,
|
||||
@@ -501,7 +501,7 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial set: miss",
|
||||
module: `package p
|
||||
s[z] { z = true }`,
|
||||
s contains z if { z = true }`,
|
||||
query: `data.p.s[true]; not data.p.s[false]`,
|
||||
hit: 0,
|
||||
miss: 2,
|
||||
@@ -509,8 +509,8 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial set: full extent cached",
|
||||
module: `package test
|
||||
p[x] { x = 1 }
|
||||
p[x] { x = 2 }
|
||||
p contains x if { x = 1 }
|
||||
p contains x if { x = 2 }
|
||||
`,
|
||||
query: "data.test.p = x; data.test.p = y",
|
||||
hit: 1,
|
||||
@@ -519,9 +519,9 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial set: all rules + each rule (non-ground var) cached",
|
||||
module: `package test
|
||||
p = r { data.test.q = x; data.test.q[y] = z; data.test.q[a] = b; r := true }
|
||||
q[x] { x = 1 }
|
||||
q[x] { x = 2 }
|
||||
p = r if { data.test.q = x; data.test.q[y] = z; data.test.q[a] = b; r := true }
|
||||
q contains x if { x = 1 }
|
||||
q contains x if { x = 2 }
|
||||
`,
|
||||
query: "data.test.p = true",
|
||||
hit: 3, // 'data.test.q[y] = z' + 2x 'data.test.q[a] = b'
|
||||
@@ -530,9 +530,9 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial set: all rules + each rule (non-ground composite) cached",
|
||||
module: `package test
|
||||
p { data.test.q = x; data.test.q[[y, 1]] = z; data.test.q[[a, 2]] = b }
|
||||
q[[x, x]] { x = 1 }
|
||||
q[[x, x]] { x = 2 }
|
||||
p if { data.test.q = x; data.test.q[[y, 1]] = z; data.test.q[[a, 2]] = b }
|
||||
q contains [x, x] if { x = 1 }
|
||||
q contains [x, x] if { x = 2 }
|
||||
`,
|
||||
query: "data.test.p = true",
|
||||
hit: 2, // 'data.test.q[[y,1]] = z' + 'data.test.q[[a, 2]] = b'
|
||||
@@ -541,9 +541,9 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial set: each rule (non-ground var), full extent cached",
|
||||
module: `package test
|
||||
p = r { data.test.q[y] = z; data.test.q = x; r := true }
|
||||
q[x] { x = 1 }
|
||||
q[x] { x = 2 }
|
||||
p = r if { data.test.q[y] = z; data.test.q = x; r := true }
|
||||
q contains x if { x = 1 }
|
||||
q contains x if { x = 2 }
|
||||
`,
|
||||
query: "data.test.p = x",
|
||||
hit: 2, // 2x 'data.test.q = x'
|
||||
@@ -552,9 +552,9 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial set: each rule (non-ground composite), full extent cached",
|
||||
module: `package test
|
||||
p = y { data.test.q[[y, 1]] = z; data.test.q = x }
|
||||
q[[x, x]] { x = 1 }
|
||||
q[[x, x]] { x = 2 }
|
||||
p = y if { data.test.q[[y, 1]] = z; data.test.q = x }
|
||||
q contains [x, x] if { x = 1 }
|
||||
q contains [x, x] if { x = 2 }
|
||||
`,
|
||||
query: "data.test.p = x",
|
||||
hit: 0,
|
||||
@@ -564,7 +564,6 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object, ref-head, ref with unification scope",
|
||||
module: `package test
|
||||
import rego.v1
|
||||
|
||||
a[x][y][z] := x + y + z if {
|
||||
some x in [1, 2]
|
||||
@@ -585,7 +584,6 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object, ref-head, ref with unification scope, component order",
|
||||
module: `package test
|
||||
import rego.v1
|
||||
|
||||
a[x][y][a][b] := i if {
|
||||
some x in [1, 2]
|
||||
@@ -606,7 +604,6 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object, ref-head, ref with unification scope, diverging key scope",
|
||||
module: `package test
|
||||
import rego.v1
|
||||
|
||||
a[x][y][z] := x + y + z if {
|
||||
some x in [1, 2]
|
||||
@@ -628,7 +625,6 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
{
|
||||
note: "partial object, ref-head, ref with unification scope, trailing vars don't contribute to key scope",
|
||||
module: `package test
|
||||
import rego.v1
|
||||
|
||||
a[x][y][z][x] := x + y + z if {
|
||||
some x in [1, 2]
|
||||
@@ -649,7 +645,6 @@ func TestTopdownVirtualCache(t *testing.T) {
|
||||
// Regression test for https://github.com/open-policy-agent/opa/issues/6926
|
||||
note: "partial object, ref-head, leaf set, ref with unification scope",
|
||||
module: `package p
|
||||
import rego.v1
|
||||
|
||||
obj.sub[x][x] contains x if some x in ["one", "two"]
|
||||
|
||||
@@ -716,7 +711,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial set",
|
||||
module: `package test
|
||||
p[v] {
|
||||
p contains v if {
|
||||
v := [1, 2, 3][_]
|
||||
}
|
||||
`,
|
||||
@@ -726,7 +721,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object",
|
||||
module: `package test
|
||||
p[i] := v {
|
||||
p[i] := v if {
|
||||
v := [1, 2, 3][i]
|
||||
}
|
||||
`,
|
||||
@@ -736,7 +731,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (const key)",
|
||||
module: `package test
|
||||
p["foo"] := v {
|
||||
p["foo"] := v if {
|
||||
v := 42
|
||||
}
|
||||
`,
|
||||
@@ -746,7 +741,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "ref head",
|
||||
module: `package test
|
||||
p.foo := v {
|
||||
p.foo := v if {
|
||||
v := 42
|
||||
}
|
||||
`,
|
||||
@@ -756,7 +751,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (ref head)",
|
||||
module: `package test
|
||||
p.q.r[i] := v {
|
||||
p.q.r[i] := v if {
|
||||
v := ["a", "b", "c"][i]
|
||||
}
|
||||
`,
|
||||
@@ -766,7 +761,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (ref head), query to obj root",
|
||||
module: `package test
|
||||
p.q.r[i] := v {
|
||||
p.q.r[i] := v if {
|
||||
v := ["a", "b", "c"][i]
|
||||
}
|
||||
`,
|
||||
@@ -776,7 +771,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (ref head), query to obj root, enumerating keys",
|
||||
module: `package test
|
||||
p.q.r[i] := v {
|
||||
p.q.r[i] := v if {
|
||||
v := ["a", "b", "c"][i]
|
||||
}
|
||||
`,
|
||||
@@ -787,7 +782,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (ref head), implicit 'true' value",
|
||||
module: `package test
|
||||
p.q.r[v] {
|
||||
p.q.r[v] if {
|
||||
v := [1, 2, 3][_]
|
||||
}
|
||||
`,
|
||||
@@ -832,7 +827,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (general ref head, multiple vars)",
|
||||
module: `package test
|
||||
p.q[x].r[i] := v {
|
||||
p.q[x].r[i] := v if {
|
||||
some i
|
||||
v := [1, 2, 3][i]
|
||||
x := ["a", "b", "c"][_]
|
||||
@@ -844,7 +839,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (general ref head, multiple vars) #2",
|
||||
module: `package test
|
||||
p[j].foo[i] := v {
|
||||
p[j].foo[i] := v if {
|
||||
v := [1, 2, 3][i]
|
||||
j := ["a", "b", "c"][_]
|
||||
}
|
||||
@@ -869,7 +864,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object with overlapping rule (defining key/value in object)",
|
||||
module: `package test
|
||||
foo.bar[i] := v {
|
||||
foo.bar[i] := v if {
|
||||
v := ["a", "b", "c"][i]
|
||||
}
|
||||
foo.bar.baz := 42
|
||||
@@ -880,7 +875,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object with overlapping rule (dee ref on overlap)",
|
||||
module: `package test
|
||||
p[k] := 1 {
|
||||
p[k] := 1 if {
|
||||
k := "foo"
|
||||
}
|
||||
p.q.r.s.t := 42
|
||||
@@ -891,7 +886,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object with overlapping rule (dee ref on overlap; conflict)",
|
||||
module: `package test
|
||||
p[k] := 1 {
|
||||
p[k] := 1 if {
|
||||
k := "q"
|
||||
}
|
||||
p.q.r.s.t := 42
|
||||
@@ -902,7 +897,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object with overlapping rule (key conflict)",
|
||||
module: `package test
|
||||
foo.bar[k] := v {
|
||||
foo.bar[k] := v if {
|
||||
k := "a"
|
||||
v := 43
|
||||
}
|
||||
@@ -914,10 +909,10 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object generating conflicting nested keys (different nested object depth)",
|
||||
module: `package test
|
||||
p.q.r {
|
||||
p.q.r if {
|
||||
true
|
||||
}
|
||||
p.q[r].s.t {
|
||||
p.q[r].s.t if {
|
||||
r := "foo"
|
||||
}`,
|
||||
query: `data = x`,
|
||||
@@ -926,10 +921,10 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object generating conflicting nested keys (different nested object depth; key conflict)",
|
||||
module: `package test
|
||||
p.q[k].s := 1 {
|
||||
p.q[k].s := 1 if {
|
||||
k := "r"
|
||||
}
|
||||
p.q[k].s.t := 1 {
|
||||
p.q[k].s.t := 1 if {
|
||||
k := "r"
|
||||
}`,
|
||||
query: `data = x`,
|
||||
@@ -938,14 +933,14 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (overlapping rules producing same values)",
|
||||
module: `package test
|
||||
p.foo.bar[i] := v {
|
||||
p.foo.bar[i] := v if {
|
||||
v := ["a", "b", "c"][i]
|
||||
}
|
||||
p.foo[i][j] := v {
|
||||
p.foo[i][j] := v if {
|
||||
i := "bar"
|
||||
v := ["a", "b", "c"][j]
|
||||
}
|
||||
p[q][i][j] := v {
|
||||
p[q][i][j] := v if {
|
||||
q := "foo"
|
||||
i := "bar"
|
||||
v := ["a", "b", "c"][j]
|
||||
@@ -957,10 +952,10 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (overlapping rules, same depth, producing non-conflicting keys)",
|
||||
module: `package test
|
||||
p.foo[i].bar := v {
|
||||
p.foo[i].bar := v if {
|
||||
v := ["a", "b", "c"][i]
|
||||
}
|
||||
p.foo.bar[i] := v {
|
||||
p.foo.bar[i] := v if {
|
||||
v := ["a", "b", "c"][i]
|
||||
}
|
||||
`,
|
||||
@@ -976,7 +971,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "partial object NOT intersecting with object value of other rule",
|
||||
module: `package test
|
||||
p.foo := {"bar": {"baz": 1}}
|
||||
p[k] := 2 {k := "other"}
|
||||
p[k] := 2 if {k := "other"}
|
||||
`,
|
||||
query: `data = x`,
|
||||
exp: `[{"x": {"test": {"p": {"foo": {"bar": {"baz": 1}}, "other": 2}}}}]`,
|
||||
@@ -985,7 +980,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "partial object NOT intersecting with object value of other rule (nested object merge along rule refs)",
|
||||
module: `package test
|
||||
p.foo.bar := {"baz": 1} # p.foo.bar == {"baz": 1}
|
||||
p[k].bar2 := v {k := "foo"; v := {"other": 2}} # p.foo.bar2 == {"other": 2}
|
||||
p[k].bar2 := v if {k := "foo"; v := {"other": 2}} # p.foo.bar2 == {"other": 2}
|
||||
`,
|
||||
query: `data = x`,
|
||||
exp: `[{"x": {"test": {"p": {"foo": {"bar": {"baz": 1}, "bar2": {"other": 2}}}}}}]`,
|
||||
@@ -994,7 +989,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "partial object intersecting with object value of other rule (not merging otherwise conflict-free obj values)",
|
||||
module: `package test
|
||||
p.foo := {"bar": {"baz": 1}} # p == {"foo": {"bar": {"baz": 1}}}
|
||||
p[k] := v {k := "foo"; v := {"bar": {"other": 2}}} # p == {"foo": {"bar": {"other": 2}}}
|
||||
p[k] := v if {k := "foo"; v := {"bar": {"other": 2}}} # p == {"foo": {"bar": {"other": 2}}}
|
||||
`,
|
||||
query: `data = x`,
|
||||
expErr: "eval_conflict_error: object keys must be unique", // conflict on key "bar" which is inside rule values, which may not be modified by other rule
|
||||
@@ -1002,8 +997,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object rules with overlapping known ref vars (no eval-time conflict)",
|
||||
module: `package test
|
||||
p[k].r1 := 1 { k := "q" }
|
||||
p[k].r2 := 2 { k := "q" }
|
||||
p[k].r1 := 1 if { k := "q" }
|
||||
p[k].r2 := 2 if { k := "q" }
|
||||
`,
|
||||
query: `data = x`,
|
||||
exp: `[{"x": {"test": {"p": {"q": {"r1": 1, "r2": 2}}}}}]`,
|
||||
@@ -1011,8 +1006,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object rules with overlapping known ref vars (eval-time conflict)",
|
||||
module: `package test
|
||||
p[k].r := 1 { k := "q" }
|
||||
p[k].r := 2 { k := "q" }
|
||||
p[k].r := 1 if { k := "q" }
|
||||
p[k].r := 2 if { k := "q" }
|
||||
`,
|
||||
query: `data = x`,
|
||||
expErr: "eval_conflict_error: object keys must be unique",
|
||||
@@ -1020,8 +1015,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object rules with overlapping known ref vars, non-overlapping object type values (eval-time conflict)",
|
||||
module: `package test
|
||||
p[k].r := {"s1": 1} { k := "q" }
|
||||
p[k].r := {"s2": 2} { k := "q" }
|
||||
p[k].r := {"s1": 1} if { k := "q" }
|
||||
p[k].r := {"s2": 2} if { k := "q" }
|
||||
`,
|
||||
query: `data = x`,
|
||||
expErr: "eval_conflict_error: object keys must be unique",
|
||||
@@ -1029,7 +1024,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object rule with object value containing var",
|
||||
module: `package test
|
||||
p.foo.q[y] := {"x": z} { y := ["bar", "baz"][_]; z := 4 }
|
||||
p.foo.q[y] := {"x": z} if { y := ["bar", "baz"][_]; z := 4 }
|
||||
`,
|
||||
query: `data = x`,
|
||||
exp: `[{"x": {"test": {"p": {"foo": {"q": {"bar": {"x": 4}, "baz": {"x": 4}}}}}}}]`,
|
||||
@@ -1037,8 +1032,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object rule with object value and intersecting key override rule (regression test #6211)",
|
||||
module: `package test
|
||||
p.foo.q[y] := {"x": 7} { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 { true }
|
||||
p.foo.q[y] := {"x": 7} if { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 if { true }
|
||||
`,
|
||||
query: `data = x`,
|
||||
expErr: "eval_conflict_error: object keys must be unique",
|
||||
@@ -1046,8 +1041,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object rule with object value and intersecting key override rule (query up to partial object) (regression test #6211)",
|
||||
module: `package test
|
||||
p.foo.q[y] := {"x": 7} { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 { true }
|
||||
p.foo.q[y] := {"x": 7} if { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 if { true }
|
||||
`,
|
||||
query: `data = x.test.p.foo.q`,
|
||||
expErr: "eval_conflict_error: object keys must be unique",
|
||||
@@ -1055,8 +1050,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object rule with object value and intersecting key override rule (query into partial object) (regression test #6211)",
|
||||
module: `package test
|
||||
p.foo.q[y] := {"x": 7} { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 { true }
|
||||
p.foo.q[y] := {"x": 7} if { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 if { true }
|
||||
`,
|
||||
query: `data.test.p.foo.q.bar = x`,
|
||||
exp: `[{"x": {"x": 7}}]`,
|
||||
@@ -1064,8 +1059,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object rule with object value and intersecting key override rule (query into key override) (regression test #6211)",
|
||||
module: `package test
|
||||
p.foo.q[y] := {"x": 7} { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 { true }
|
||||
p.foo.q[y] := {"x": 7} if { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 if { true }
|
||||
`,
|
||||
query: `data.test.p.foo.q.baz = x`,
|
||||
expErr: "eval_conflict_error: object keys must be unique",
|
||||
@@ -1073,8 +1068,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object rule with object value and intersecting key override rule (query into partial object, enumeration) (regression test #6211)",
|
||||
module: `package test
|
||||
p.foo.q[y] := {"x": 7} { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 { true }
|
||||
p.foo.q[y] := {"x": 7} if { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 if { true }
|
||||
`,
|
||||
query: `data.test.p.foo.q[z] = x`,
|
||||
expErr: "eval_conflict_error: object keys must be unique",
|
||||
@@ -1082,8 +1077,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object rule with object value and intersecting key override rule (query into partial object, enumeration #2) (regression test #6211)",
|
||||
module: `package test
|
||||
p.foo.q[y] := {"x": 7} { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 { true }
|
||||
p.foo.q[y] := {"x": 7} if { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 if { true }
|
||||
`,
|
||||
query: `data.test.p.foo.q[z].x = x`,
|
||||
expErr: "eval_conflict_error: object keys must be unique",
|
||||
@@ -1091,8 +1086,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object rule with object value and intersecting key override rule (query into key override, enumeration) (regression test #6211)",
|
||||
module: `package test
|
||||
p.foo.q[y] := {"x": 7} { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 { true }
|
||||
p.foo.q[y] := {"x": 7} if { y := ["bar", "baz"][_] }
|
||||
p.foo.q.baz.y = 9 if { true }
|
||||
`,
|
||||
query: `data.test.p.foo.q.baz[z] = x`,
|
||||
expErr: "eval_conflict_error: object keys must be unique",
|
||||
@@ -1101,7 +1096,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object (ref head)",
|
||||
module: `package test
|
||||
p.q[r] := 1 { r := "foo" }
|
||||
p.q[r] := 1 if { r := "foo" }
|
||||
`,
|
||||
query: `data.test.p.q.foo = x`,
|
||||
exp: `[{"x": 1}]`,
|
||||
@@ -1109,7 +1104,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object (ref head) and object value",
|
||||
module: `package test
|
||||
p.q[r] := x {
|
||||
p.q[r] := x if {
|
||||
r := "foo"
|
||||
x := {"bar": {"baz": 1}}
|
||||
}
|
||||
@@ -1120,7 +1115,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object starting-point (general ref head) up to array value",
|
||||
module: `package test
|
||||
p.q[r].s[t].u := x {
|
||||
p.q[r].s[t].u := x if {
|
||||
obj := {
|
||||
"foo": {
|
||||
"do": ["a", "b", "c"],
|
||||
@@ -1140,7 +1135,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object mid-point (general ref head) up to array value",
|
||||
module: `package test
|
||||
p.q[r].s[t].u := x {
|
||||
p.q[r].s[t].u := x if {
|
||||
obj := {
|
||||
"foo": {
|
||||
"do": ["a", "b", "c"],
|
||||
@@ -1160,7 +1155,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object (general ref head) up to array value",
|
||||
module: `package test
|
||||
p.q[r].s[t].u := x {
|
||||
p.q[r].s[t].u := x if {
|
||||
obj := {
|
||||
"foo": {
|
||||
"do": ["a", "b", "c"],
|
||||
@@ -1180,7 +1175,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object (general ref head) and array value",
|
||||
module: `package test
|
||||
p.q[r].s[t].u := x {
|
||||
p.q[r].s[t].u := x if {
|
||||
obj := {
|
||||
"foo": {
|
||||
"do": ["a", "b", "c"],
|
||||
@@ -1201,7 +1196,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "query up to (ref head), but not into partial set",
|
||||
module: `package test
|
||||
import future.keywords
|
||||
p.q.r contains s { {"foo", "bar", "bax"}[s] }
|
||||
p.q.r contains s if { {"foo", "bar", "bax"}[s] }
|
||||
`,
|
||||
query: `data.test.p = x`,
|
||||
exp: `[{"x": {"q": {"r": ["bar", "bax", "foo"]}}}]`,
|
||||
@@ -1210,7 +1205,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "deep query up to (ref mid-point), but not into partial set",
|
||||
module: `package test
|
||||
import future.keywords
|
||||
p.q.r contains s { {"foo", "bar", "bax"}[s] }
|
||||
p.q.r contains s if { {"foo", "bar", "bax"}[s] }
|
||||
`,
|
||||
query: `data.test.p.q = x`,
|
||||
exp: `[{"x": {"r": ["bar", "bax", "foo"]}}]`,
|
||||
@@ -1219,7 +1214,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "deep query up to (ref tail), but not into partial set",
|
||||
module: `package test
|
||||
import future.keywords
|
||||
p.q.r contains s { {"foo", "bar", "bax"}[s] }
|
||||
p.q.r contains s if { {"foo", "bar", "bax"}[s] }
|
||||
`,
|
||||
query: `data.test.p.q.r = x`,
|
||||
exp: `[{"x": ["bar", "bax", "foo"]}]`,
|
||||
@@ -1228,7 +1223,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "deep query into partial set",
|
||||
module: `package test
|
||||
import future.keywords
|
||||
p.q contains r { {"foo", "bar", "bax"}[r] }
|
||||
p.q contains r if { {"foo", "bar", "bax"}[r] }
|
||||
`,
|
||||
query: `data.test.p.q.foo = x`,
|
||||
exp: `[{"x": "foo"}]`,
|
||||
@@ -1236,7 +1231,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{ // enumeration
|
||||
note: "deep query into partial object and object value, full depth, enumeration on object value",
|
||||
module: `package test
|
||||
p.q[r] := x {
|
||||
p.q[r] := x if {
|
||||
r := ["foo", "bar"][_]
|
||||
x := {"s": {"do": 0, "re": 1, "mi": 2}}
|
||||
}
|
||||
@@ -1247,7 +1242,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{ // enumeration
|
||||
note: "deep query into partial object and object value, full depth, enumeration on rule path and object value",
|
||||
module: `package test
|
||||
p.q[r] := x {
|
||||
p.q[r] := x if {
|
||||
r := ["foo", "bar"][_]
|
||||
x := {"s": {"do": 0, "re": 1, "mi": 2}}
|
||||
}
|
||||
@@ -1259,7 +1254,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "deep query into partial object (ref head) and set value",
|
||||
module: `package test
|
||||
import future.keywords
|
||||
p.q contains t {
|
||||
p.q contains t if {
|
||||
{"do", "re", "mi"}[t]
|
||||
}
|
||||
`,
|
||||
@@ -1270,7 +1265,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "deep query into partial object (general ref head) and set value",
|
||||
module: `package test
|
||||
import future.keywords
|
||||
p.q[r] contains t {
|
||||
p.q[r] contains t if {
|
||||
r := ["foo", "bar"][_]
|
||||
{"do", "re", "mi"}[t]
|
||||
}
|
||||
@@ -1282,7 +1277,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "deep query into partial object (general ref head, static tail) and set value",
|
||||
module: `package test
|
||||
import future.keywords
|
||||
p.q[r].s contains t {
|
||||
p.q[r].s contains t if {
|
||||
r := ["foo", "bar"][_]
|
||||
{"do", "re", "mi"}[t]
|
||||
}
|
||||
@@ -1294,7 +1289,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "deep query into general ref to set value",
|
||||
module: `package test
|
||||
import future.keywords
|
||||
p.q[r].s contains t {
|
||||
p.q[r].s contains t if {
|
||||
r := ["foo", "bar"][_]
|
||||
t := ["do", "re", "mi"][_]
|
||||
}
|
||||
@@ -1305,7 +1300,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into general ref to object value",
|
||||
module: `package test
|
||||
p.q[r].s[t] := u {
|
||||
p.q[r].s[t] := u if {
|
||||
r := ["foo", "bar"][_]
|
||||
t := ["do", "re", "mi"][u]
|
||||
}
|
||||
@@ -1317,7 +1312,7 @@ func TestPartialRule(t *testing.T) {
|
||||
note: "deep query into general ref enumerating set values",
|
||||
module: `package test
|
||||
import future.keywords
|
||||
p.q[r].s contains t {
|
||||
p.q[r].s contains t if {
|
||||
r := ["foo", "bar"][_]
|
||||
{"do", "re", "mi"}[t]
|
||||
}
|
||||
@@ -1329,7 +1324,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object and object value, non-tail var",
|
||||
module: `package test
|
||||
p.q[r].s := x {
|
||||
p.q[r].s := x if {
|
||||
r := "foo"
|
||||
x := {"bar": {"baz": 1}}
|
||||
}
|
||||
@@ -1340,7 +1335,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, on first var in ref",
|
||||
module: `package test
|
||||
p.q[r].s := 1 { r := "foo" }
|
||||
p.q[r].s := 1 if { r := "foo" }
|
||||
`,
|
||||
query: `data.test.p.q.foo = x`,
|
||||
exp: `[{"x": {"s": 1}}]`,
|
||||
@@ -1348,7 +1343,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, beyond first var in ref",
|
||||
module: `package test
|
||||
p.q[r].s := 1 { r := "foo" }
|
||||
p.q[r].s := 1 if { r := "foo" }
|
||||
`,
|
||||
query: `data.test.p.q.foo.s = x`,
|
||||
exp: `[{"x": 1}]`,
|
||||
@@ -1356,7 +1351,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, shallow rule ref",
|
||||
module: `package test
|
||||
p.q[r][s] := 1 { r := "foo"; s := "bar" }
|
||||
p.q[r][s] := 1 if { r := "foo"; s := "bar" }
|
||||
`,
|
||||
query: `data.test.p.q.foo = x`,
|
||||
exp: `[{"x": {"bar": 1}}]`,
|
||||
@@ -1364,7 +1359,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, shallow rule ref, multiple keys",
|
||||
module: `package test
|
||||
p.q[r][s] := t { l := ["do", "re", "mi"]; r := "foo"; s := l[t] }
|
||||
p.q[r][s] := t if { l := ["do", "re", "mi"]; r := "foo"; s := l[t] }
|
||||
`,
|
||||
query: `data.test.p.q.foo = x`,
|
||||
exp: `[{"x": {"do": 0, "re": 1, "mi": 2}}]`,
|
||||
@@ -1372,7 +1367,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, beyond first var in ref, multiple vars",
|
||||
module: `package test
|
||||
p.q[r][s] := 1 { r := "foo"; s := "bar" }
|
||||
p.q[r][s] := 1 if { r := "foo"; s := "bar" }
|
||||
`,
|
||||
query: `data.test.p.q.foo.bar = x`,
|
||||
exp: `[{"x": 1}]`,
|
||||
@@ -1380,7 +1375,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, beyond first var in ref, multiple vars",
|
||||
module: `package test
|
||||
p.q[r][s].t := 1 { r := "foo"; s := "bar" }
|
||||
p.q[r][s].t := 1 if { r := "foo"; s := "bar" }
|
||||
`,
|
||||
query: `data.test.p.q.foo.bar = x`,
|
||||
exp: `[{"x": {"t": 1}}]`,
|
||||
@@ -1388,7 +1383,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query to partial object, overlapping rules (key override), no dynamic ref",
|
||||
module: `package test
|
||||
p.q[r] := 1 { r := "foo" }
|
||||
p.q[r] := 1 if { r := "foo" }
|
||||
p.q.r := 2
|
||||
`,
|
||||
query: `data.test.p.q = x`,
|
||||
@@ -1397,7 +1392,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, overlapping rules (key override), no dynamic ref",
|
||||
module: `package test
|
||||
p.q[r] := 1 { r := "foo" }
|
||||
p.q[r] := 1 if { r := "foo" }
|
||||
p.q.r := 2
|
||||
`,
|
||||
query: `data.test.p.q.r = x`,
|
||||
@@ -1406,8 +1401,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, overlapping rules, no dynamic ref",
|
||||
module: `package test
|
||||
p.q[r] := 1 { r := "foo" }
|
||||
p.q[r] := 2 { r := "bar" }
|
||||
p.q[r] := 1 if { r := "foo" }
|
||||
p.q[r] := 2 if { r := "bar" }
|
||||
`,
|
||||
query: `data.test.p.q.foo = x`,
|
||||
exp: `[{"x": 1}]`,
|
||||
@@ -1415,8 +1410,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, overlapping rules with same key/value, no dynamic ref",
|
||||
module: `package test
|
||||
p.q[r] := 1 { r := "foo" }
|
||||
p.q[r] := 1 { r := "foo" }
|
||||
p.q[r] := 1 if { r := "foo" }
|
||||
p.q[r] := 1 if { r := "foo" }
|
||||
`,
|
||||
query: `data.test.p.q.foo = x`,
|
||||
exp: `[{"x": 1}]`,
|
||||
@@ -1424,8 +1419,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, overlapping rules, dynamic ref",
|
||||
module: `package test
|
||||
p.q[r].s := 1 { r := "r" }
|
||||
p.q.r[s] := 2 { s := "foo" }
|
||||
p.q[r].s := 1 if { r := "r" }
|
||||
p.q.r[s] := 2 if { s := "foo" }
|
||||
`,
|
||||
query: `data.test.p.q.r = x`,
|
||||
exp: `[{"x": {"s": 1, "foo": 2}}]`,
|
||||
@@ -1433,8 +1428,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, overlapping rules with same key/value, dynamic ref",
|
||||
module: `package test
|
||||
p.q[r].s := 1 { r := "r" }
|
||||
p.q.r[s] := 1 { s := "s" }
|
||||
p.q[r].s := 1 if { r := "r" }
|
||||
p.q.r[s] := 1 if { s := "s" }
|
||||
`,
|
||||
query: `data.test.p.q.r = x`,
|
||||
exp: `[{"x": {"s": 1}}]`,
|
||||
@@ -1443,7 +1438,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "shallow query into general ref, key enumeration",
|
||||
module: `package test
|
||||
p.q[r].s[t] := u {
|
||||
p.q[r].s[t] := u if {
|
||||
r := ["a", "b", "c"][_]
|
||||
t := ["d", "e", "f"][u]
|
||||
}`,
|
||||
@@ -1455,8 +1450,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "query to partial object, overlapping rules, dynamic ref, key enumeration",
|
||||
module: `package test
|
||||
p.q[r].s := 1 { r := "foo" }
|
||||
p.q[r].s := 2 { r := "bar" }
|
||||
p.q[r].s := 1 if { r := "foo" }
|
||||
p.q[r].s := 2 if { r := "bar" }
|
||||
`,
|
||||
query: `data.test.p.q[i] = x`,
|
||||
exp: `[{"i": "bar", "x": {"s": 2}}, {"i": "foo", "x": {"s": 1}}]`,
|
||||
@@ -1464,8 +1459,8 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "deep query into partial object, overlapping rules, dynamic ref, key enumeration",
|
||||
module: `package test
|
||||
p.q[r].s := 1 { r := "foo" }
|
||||
p.q[r].s := 2 { r := "bar" }
|
||||
p.q[r].s := 1 if { r := "foo" }
|
||||
p.q[r].s := 2 if { r := "bar" }
|
||||
`,
|
||||
query: `data.test.p.q[i].s = x`,
|
||||
exp: `[{"i": "bar", "x": 2}, {"i": "foo", "x": 1}]`,
|
||||
@@ -1474,7 +1469,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object generating conflicting keys",
|
||||
module: `package test
|
||||
p[k] := x {
|
||||
p[k] := x if {
|
||||
k := "foo"
|
||||
x := [1, 2][_]
|
||||
}`,
|
||||
@@ -1484,7 +1479,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (ref head) generating conflicting keys (dots in head)",
|
||||
module: `package test
|
||||
p.q[k] := x {
|
||||
p.q[k] := x if {
|
||||
k := "foo"
|
||||
x := [1, 2][_]
|
||||
}`,
|
||||
@@ -1494,7 +1489,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (general ref head) generating conflicting nested keys",
|
||||
module: `package test
|
||||
p.q[k].s := x {
|
||||
p.q[k].s := x if {
|
||||
k := "foo"
|
||||
x := [1, 2][_]
|
||||
}`,
|
||||
@@ -1504,7 +1499,7 @@ func TestPartialRule(t *testing.T) {
|
||||
{
|
||||
note: "partial object (general ref head) generating conflicting ref vars",
|
||||
module: `package test
|
||||
p.q[k].s := x {
|
||||
p.q[k].s := x if {
|
||||
k := ["foo", "foo"][x]
|
||||
}`,
|
||||
query: `data = x`,
|
||||
|
||||
@@ -195,10 +195,11 @@ func ExampleQuery_PartialRun() {
|
||||
modules := map[string]*ast.Module{
|
||||
"authz.rego": ast.MustParseModule(`
|
||||
package example
|
||||
import rego.v1
|
||||
|
||||
default allow = false
|
||||
|
||||
allow {
|
||||
allow if {
|
||||
role = data.roles[i]
|
||||
input.group = role.groups[j]
|
||||
input.permission = role.permissions[k]
|
||||
|
||||
+14
-8
@@ -23,7 +23,7 @@ func TestTopDownPrint(t *testing.T) {
|
||||
module: `
|
||||
package test
|
||||
|
||||
p { print() }
|
||||
p if { print() }
|
||||
`,
|
||||
exp: "\n",
|
||||
},
|
||||
@@ -32,7 +32,7 @@ func TestTopDownPrint(t *testing.T) {
|
||||
module: `
|
||||
package test
|
||||
|
||||
p {
|
||||
p if {
|
||||
x := "world"
|
||||
print("hello", x)
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func TestTopDownPrint(t *testing.T) {
|
||||
|
||||
xs := [1,2]
|
||||
|
||||
p {
|
||||
p if {
|
||||
print("the value of xs is:", xs)
|
||||
}
|
||||
`,
|
||||
@@ -57,7 +57,7 @@ func TestTopDownPrint(t *testing.T) {
|
||||
module: `
|
||||
package test
|
||||
|
||||
p {
|
||||
p if {
|
||||
print("the value of foo is:", input.foo)
|
||||
}
|
||||
`,
|
||||
@@ -68,7 +68,7 @@ func TestTopDownPrint(t *testing.T) {
|
||||
module: `
|
||||
package test
|
||||
|
||||
p {
|
||||
p if {
|
||||
print("the value of foo is:", [input.foo])
|
||||
}
|
||||
`,
|
||||
@@ -79,7 +79,7 @@ func TestTopDownPrint(t *testing.T) {
|
||||
module: `
|
||||
package test
|
||||
|
||||
p {
|
||||
p if {
|
||||
print("div by zero:", 1/0) # divide by zero will be undefined unless strict-builtin-errors are enabled
|
||||
}
|
||||
`,
|
||||
@@ -93,7 +93,7 @@ func TestTopDownPrint(t *testing.T) {
|
||||
xs := {1}
|
||||
ys := {"a"}
|
||||
|
||||
p {
|
||||
p if {
|
||||
print(walk(xs), walk(ys))
|
||||
}
|
||||
`,
|
||||
@@ -108,7 +108,13 @@ func TestTopDownPrint(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.note, func(t *testing.T) {
|
||||
|
||||
c := ast.MustCompileModulesWithOpts(map[string]string{"test.rego": tc.module}, ast.CompileOpts{EnablePrintStatements: true})
|
||||
c := ast.MustCompileModulesWithOpts(map[string]string{"test.rego": tc.module},
|
||||
ast.CompileOpts{
|
||||
EnablePrintStatements: true,
|
||||
ParserOptions: ast.ParserOptions{
|
||||
AllFutureKeywords: true,
|
||||
},
|
||||
})
|
||||
buf := bytes.NewBuffer(nil)
|
||||
q := NewQuery(ast.MustParseBody("data.test.p = x")).
|
||||
WithPrintHook(NewPrintHook(buf)).
|
||||
|
||||
@@ -254,12 +254,12 @@ func initTracerTestQuery() *Query {
|
||||
compiler := compileModules([]string{
|
||||
`package x
|
||||
|
||||
p {
|
||||
p if {
|
||||
a := [1, 2, 3]
|
||||
f(a[_])
|
||||
}
|
||||
|
||||
f(x) {
|
||||
f(x) if {
|
||||
x == 3
|
||||
}
|
||||
|
||||
|
||||
+580
-581
File diff suppressed because it is too large
Load Diff
+200
-197
File diff suppressed because it is too large
Load Diff
+36
-30
@@ -56,8 +56,8 @@ func TestEventEqual(t *testing.T) {
|
||||
func TestPrettyTrace(t *testing.T) {
|
||||
module := `package test
|
||||
|
||||
p { q[x]; plus(x, 1, n) }
|
||||
q[x] { x = data.a[_] }`
|
||||
p if { q[x]; plus(x, 1, n) }
|
||||
q contains x if { x = data.a[_] }`
|
||||
|
||||
ctx := context.Background()
|
||||
compiler := compileModules([]string{module})
|
||||
@@ -116,8 +116,8 @@ Redo data.test.p = _
|
||||
func TestPrettyTraceWithLocation(t *testing.T) {
|
||||
module := `package test
|
||||
|
||||
p { q[x]; plus(x, 1, n) }
|
||||
q[x] { x = data.a[_] }`
|
||||
p if { q[x]; plus(x, 1, n) }
|
||||
q contains x if { x = data.a[_] }`
|
||||
|
||||
ctx := context.Background()
|
||||
compiler := compileModules([]string{module})
|
||||
@@ -176,17 +176,21 @@ query:3 | | Redo data.test.q[x]
|
||||
func TestPrettyTraceWithLocationTruncatedPaths(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
compiler := ast.MustCompileModules(map[string]string{
|
||||
compiler := ast.MustCompileModulesWithOpts(map[string]string{
|
||||
"authz_bundle/com/foo/bar/baz/qux/acme/corp/internal/authz/policies/abac/v1/beta/policy.rego": `package test
|
||||
|
||||
import data.utils.q
|
||||
|
||||
p = true { q[x]; plus(x, 1, n) }
|
||||
p = true if { q[x]; plus(x, 1, n) }
|
||||
`,
|
||||
"authz_bundle/com/foo/bar/baz/qux/acme/corp/internal/authz/policies/utils/utils.rego": `package utils
|
||||
|
||||
q[x] { x = data.a[_] }
|
||||
q contains x if { x = data.a[_] }
|
||||
`,
|
||||
}, ast.CompileOpts{
|
||||
ParserOptions: ast.ParserOptions{
|
||||
AllFutureKeywords: true,
|
||||
},
|
||||
})
|
||||
data := loadSmallTestData()
|
||||
store := inmem.NewFromObject(data)
|
||||
@@ -243,13 +247,13 @@ authz_bundle/...ternal/authz/policies/abac/v1/beta/policy.rego:5 | | Redo da
|
||||
func TestPrettyTracePartialWithLocationTruncatedPaths(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
compiler := ast.MustCompileModules(map[string]string{
|
||||
compiler := ast.MustCompileModulesWithOpts(map[string]string{
|
||||
"authz_bundle/com/foo/bar/baz/qux/acme/corp/internal/authz/policies/rbac/v1/beta/policy.rego": `
|
||||
package example_rbac
|
||||
|
||||
default allow = false
|
||||
|
||||
allow {
|
||||
allow if {
|
||||
data.utils.user_has_role[role_name]
|
||||
|
||||
data.utils.role_has_permission[role_name]
|
||||
@@ -259,19 +263,23 @@ func TestPrettyTracePartialWithLocationTruncatedPaths(t *testing.T) {
|
||||
"authz_bundle/com/foo/bar/baz/qux/acme/corp/internal/authz/policies/utils/user.rego": `
|
||||
package utils
|
||||
|
||||
user_has_role[role_name] {
|
||||
user_has_role contains role_name if {
|
||||
role_binding = data.bindings[_]
|
||||
role_binding.role = role_name
|
||||
role_binding.user = input.subject.user
|
||||
}
|
||||
|
||||
role_has_permission[role_name] {
|
||||
role_has_permission contains role_name if {
|
||||
role = data.roles[_]
|
||||
role.name = role_name
|
||||
role.operation = input.action.operation
|
||||
role.resource = input.action.resource
|
||||
}
|
||||
`,
|
||||
}, ast.CompileOpts{
|
||||
ParserOptions: ast.ParserOptions{
|
||||
AllFutureKeywords: true,
|
||||
},
|
||||
})
|
||||
|
||||
var data map[string]interface{}
|
||||
@@ -414,9 +422,9 @@ func TestTraceDuplicate(t *testing.T) {
|
||||
// Having `p[1]` queried first will side-step the caching optimization.
|
||||
module := `package test
|
||||
|
||||
p[1]
|
||||
p[2]
|
||||
p[1]
|
||||
p contains 1
|
||||
p contains 2
|
||||
p contains 1
|
||||
`
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -453,8 +461,8 @@ func TestTraceDuplicate(t *testing.T) {
|
||||
func TestTraceNote(t *testing.T) {
|
||||
module := `package test
|
||||
|
||||
p { q[x]; plus(x, 1, n); trace(sprintf("n=%v", [n])) }
|
||||
q[x] { x = data.a[_] }`
|
||||
p if { q[x]; plus(x, 1, n); trace(sprintf("n=%v", [n])) }
|
||||
q contains x if { x = data.a[_] }`
|
||||
|
||||
ctx := context.Background()
|
||||
compiler := compileModules([]string{module})
|
||||
@@ -518,8 +526,8 @@ Redo data.test.p = _
|
||||
func TestTraceNoteWithLocation(t *testing.T) {
|
||||
module := `package test
|
||||
|
||||
p { q[x]; plus(x, 1, n); trace(sprintf("n=%v", [n])) }
|
||||
q[x] { x = data.a[_] }`
|
||||
p if { q[x]; plus(x, 1, n); trace(sprintf("n=%v", [n])) }
|
||||
q contains x if { x = data.a[_] }`
|
||||
|
||||
ctx := context.Background()
|
||||
compiler := compileModules([]string{module})
|
||||
@@ -761,7 +769,7 @@ func TestTraceEveryEvaluation(t *testing.T) {
|
||||
note: "empty domain",
|
||||
query: "data.test.p = x",
|
||||
module: `package test
|
||||
p { every k, v in [] { k != v } }`,
|
||||
p if { every k, v in [] { k != v } }`,
|
||||
exp: events(
|
||||
`Enter every __local0__, __local1__ in __local2__ { neq(__local0__, __local1__) } {} (qid=2, pqid=1)`,
|
||||
`Exit every __local0__, __local1__ in __local2__ { neq(__local0__, __local1__) } {} (qid=2, pqid=1)`,
|
||||
@@ -771,7 +779,7 @@ func TestTraceEveryEvaluation(t *testing.T) {
|
||||
note: "successful eval",
|
||||
query: "data.test.p = x",
|
||||
module: `package test
|
||||
p { every k, v in [1] { k != v } }`,
|
||||
p if { every k, v in [1] { k != v } }`,
|
||||
exp: events(
|
||||
`Enter every __local0__, __local1__ in __local2__ { neq(__local0__, __local1__) } {} (qid=2, pqid=1)`,
|
||||
`Enter neq(__local0__, __local1__) {} (qid=3, pqid=2)`,
|
||||
@@ -784,7 +792,7 @@ func TestTraceEveryEvaluation(t *testing.T) {
|
||||
note: "failure in first body query",
|
||||
query: "data.test.p = x",
|
||||
module: `package test
|
||||
p { every v in [1, 2] { 1 != v } }`,
|
||||
p if { every v in [1, 2] { 1 != v } }`,
|
||||
exp: events(
|
||||
`Enter every __local0__, __local1__ in __local2__ { neq(1, __local1__) } {} (qid=2, pqid=1)`,
|
||||
`Enter neq(1, __local1__) {} (qid=3, pqid=2)`,
|
||||
@@ -797,7 +805,7 @@ func TestTraceEveryEvaluation(t *testing.T) {
|
||||
note: "failure in last body query",
|
||||
query: "data.test.p = x",
|
||||
module: `package test
|
||||
p { every v in [0, 1] { 1 != v } }`,
|
||||
p if { every v in [0, 1] { 1 != v } }`,
|
||||
exp: events(
|
||||
`Enter every __local0__, __local1__ in __local2__ { neq(1, __local1__) } {} (qid=2, pqid=1)`,
|
||||
`Enter neq(1, __local1__) {} (qid=3, pqid=2)`,
|
||||
@@ -812,7 +820,7 @@ func TestTraceEveryEvaluation(t *testing.T) {
|
||||
|
||||
for _, tc := range tests {
|
||||
|
||||
opts := ast.CompileOpts{ParserOptions: ast.ParserOptions{FutureKeywords: []string{"every"}}}
|
||||
opts := ast.CompileOpts{ParserOptions: ast.ParserOptions{AllFutureKeywords: true}}
|
||||
compiler, err := ast.CompileModulesWithOpt(map[string]string{"test.rego": tc.module}, opts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1026,7 +1034,7 @@ func TestTraceInput(t *testing.T) {
|
||||
module := `
|
||||
package test
|
||||
|
||||
rule = x {
|
||||
rule = x if {
|
||||
x = input.v
|
||||
}
|
||||
`
|
||||
@@ -1068,7 +1076,7 @@ func TestTracePlug(t *testing.T) {
|
||||
module := `
|
||||
package test
|
||||
|
||||
rule[[a, b]] {
|
||||
rule contains [a, b] if {
|
||||
a = [1, 2][_]
|
||||
b = [2, 1][_]
|
||||
}
|
||||
@@ -1158,14 +1166,14 @@ func TestPrettyTraceWithLocationForMetadataCall(t *testing.T) {
|
||||
module := `package test
|
||||
rule_no_output_var := rego.metadata.rule()
|
||||
|
||||
rule_with_output_var {
|
||||
rule_with_output_var if {
|
||||
foo := rego.metadata.rule()
|
||||
foo == {}
|
||||
}
|
||||
|
||||
chain_no_output_var := rego.metadata.chain()
|
||||
|
||||
chain_with_output_var {
|
||||
chain_with_output_var if {
|
||||
foo := rego.metadata.chain()
|
||||
foo == []
|
||||
}`
|
||||
@@ -1246,7 +1254,7 @@ query:1 | Redo data.test = _
|
||||
func TestPrettyTraceWithUnifyOps(t *testing.T) {
|
||||
module := `package test
|
||||
|
||||
p[x] {
|
||||
p contains x if {
|
||||
x = 1
|
||||
}`
|
||||
|
||||
@@ -1303,7 +1311,6 @@ func removeUnifyOps(trace []*Event) (result []*Event) {
|
||||
func TestPrettyTraceWithLocalVars(t *testing.T) {
|
||||
{
|
||||
module := `package test
|
||||
import rego.v1
|
||||
|
||||
p if {
|
||||
x := 1
|
||||
@@ -1388,7 +1395,6 @@ Redo data.test = _ {_: {"p": true}}
|
||||
func TestPrettyTraceExprVars(t *testing.T) {
|
||||
{
|
||||
module := `package test
|
||||
import rego.v1
|
||||
|
||||
p if {
|
||||
x := 1
|
||||
|
||||
Reference in New Issue
Block a user