Skip to content

Commit

Permalink
Updating Wasm tests
Browse files Browse the repository at this point in the history
Signed-off-by: Johan Fylling <[email protected]>
  • Loading branch information
johanfylling committed Nov 25, 2024
1 parent 713d18d commit 3698c00
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package format

import (
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/types"
v1 "github.com/open-policy-agent/opa/v1/format"
"github.com/open-policy-agent/opa/v1/types"
)

// Opts lets you control the code formatting via `AstWithOpts()`.
Expand Down
22 changes: 11 additions & 11 deletions internal/wasm/sdk/opa/opa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func TestOPA(t *testing.T) {
},
{
Description: "Runtime error/var assignment conflict",
Policy: `a = "b" { input > 1 }
a = "c" { input > 2 }`,
Policy: `a = "b" if { input > 1 }
a = "c" if { input > 2 }`,
Query: "data.p.a = x",
Evals: []Eval{
{Input: "3"},
Expand All @@ -131,10 +131,10 @@ a = "c" { input > 2 }`,
Description: "Runtime error/else conflict-1",
Query: `data.p.q`,
Policy: `
q {
q if {
false
}
else = true {
else = true if {
true
}
q = false`,
Expand All @@ -145,16 +145,16 @@ a = "c" { input > 2 }`,
Description: "Runtime error/else conflict-2",
Query: `data.p.q`,
Policy: `
q {
q if {
false
}
else = false {
else = false if {
true
}
q {
q if {
false
}
else = true {
else = true if {
true
}`,
Evals: []Eval{{}},
Expand All @@ -167,7 +167,7 @@ a = "c" { input > 2 }`,
Description: "Only input changing, regex.match",
Policy: `
default hello = false
hello {
hello if {
regex.match("^world$", input.message)
}`,
Query: "data.p.hello = x",
Expand All @@ -180,7 +180,7 @@ a = "c" { input > 2 }`,
Description: "Only input changing, glob.match",
Policy: `
default hello = false
hello {
hello if {
glob.match("world", [":"], input.message)
}`,
Query: "data.p.hello = x",
Expand Down Expand Up @@ -215,7 +215,7 @@ a = "c" { input > 2 }`,
{
Description: "mpd init problem (#3110)",
Query: `data.p.main = x`,
Policy: `main { numbers.range(1, 2)[_] == 2 }`,
Policy: `main if { numbers.range(1, 2)[_] == 2 }`,
Evals: []Eval{
{Result: `{{"x": true}}`},
{Result: `{{"x": true}}`},
Expand Down
10 changes: 5 additions & 5 deletions v1/rego/rego_wasmtarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestPrepareAndEvalWithWasmTarget(t *testing.T) {
mod := `
package test
default p = false
p {
p if {
input.x == 1
}
`
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestPrepareAndEvalWithWasmTargetModulesOnCompiler(t *testing.T) {
mod := `
package test
default p = false
p {
p if {
input.x == data.x.p
}
`
Expand Down Expand Up @@ -161,21 +161,21 @@ func TestEvalWithContextTimeout(t *testing.T) {
// but calls the topdown function from the wasm instance's execution.
// Also, it uses the topdown.Cancel mechanism for cancellation.
cidrExpand := `package p
allow {
allow if {
net.cidr_expand("1.0.0.0/1")
}`

// Also a host function, but uses context.Context for cancellation.
httpSend := fmt.Sprintf(`package p
allow {
allow if {
http.send({"method": "get", "url": "%s", "raise_error": true})
}`,
ts.URL)

// This is a natively-implemented (for the wasm target) function that
// takes long.
numbersRange := `package p
allow {
allow if {
numbers.range(1, 1e8)[_] == 1e8
}`

Expand Down

0 comments on commit 3698c00

Please sign in to comment.