mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
a34c5672bc
This was introduced in #3624: turns out the eval command's code only passed parsedInput into the rego package, and that only looked at rawInput when feeding it into the wasm engine. The approach taken here is to make the rego package more robust: It should do the right thing if parsedInput is provided for an eval under the wasm target: the parsing work was already done, let's not dischard it. Fixes #3666. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
// Copyright 2021 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build opa_wasm
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestEvalWithJSONInputFile(t *testing.T) {
|
|
|
|
input := `{
|
|
"foo": "a",
|
|
"b": [
|
|
{
|
|
"a": 1,
|
|
"b": [1, 2, 3],
|
|
"c": null
|
|
}
|
|
]
|
|
}`
|
|
query := "input.b[0].a == 1"
|
|
|
|
for _, tgt := range []string{"rego", "wasm"} {
|
|
t.Run(tgt, func(t *testing.T) {
|
|
params := newEvalCommandParams()
|
|
params.target.Set(tgt)
|
|
err := testEvalWithInputFile(t, input, query, params)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %s", err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestEvalWithYAMLInputFile(t *testing.T) {
|
|
input := `
|
|
foo: a
|
|
b:
|
|
- a: 1
|
|
b: [1, 2, 3]
|
|
c:
|
|
`
|
|
query := "input.b[0].a == 1"
|
|
|
|
for _, tgt := range []string{"rego", "wasm"} {
|
|
t.Run(tgt, func(t *testing.T) {
|
|
params := newEvalCommandParams()
|
|
params.target.Set(tgt)
|
|
err := testEvalWithInputFile(t, input, query, params)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %s", err)
|
|
}
|
|
})
|
|
}
|
|
}
|