forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_test.go
39 lines (34 loc) · 1.15 KB
/
prepare_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
// Copyright 2023 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.
package rego_test
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/rego"
"github.com/open-policy-agent/opa/topdown"
"github.com/open-policy-agent/opa/types"
)
// NOTE(sr): These test are here because the only cases where PrepareOption are
// used is outside of the rego package. Testing them within the rego package
// would be less realistic.
func TestPrepareOption(t *testing.T) {
t.Run("BuiltinFuncs", func(t *testing.T) {
bi := map[string]*topdown.Builtin{
"count": {
Decl: ast.BuiltinMap["count"],
Func: topdown.GetBuiltin("count"),
},
}
pc := ®o.PrepareConfig{}
rego.WithBuiltinFuncs(bi)(pc)
act, exp := pc.BuiltinFuncs(), bi
if diff := cmp.Diff(exp, act,
cmpopts.IgnoreUnexported(ast.Builtin{}, types.Function{}),
cmpopts.IgnoreFields(topdown.Builtin{}, "Func")); diff != "" {
t.Errorf("unexpected result (-want, +got):\n%s", diff)
}
})
}