forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval_wasmtarget_test.go
59 lines (51 loc) · 1.06 KB
/
eval_wasmtarget_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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)
}
})
}
}