mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
topdown/builtins: Refactor registration functions and signatures (#5225)
* topdown/aggregates: Refactor to newer style. * topdown/arithmetic: Refactor to newer style. * topdown/array: Refactor to newer style. * topdown/binary: Refactor to newer style. * topdown/crypto: Refactor to newer style. * topdown/casts: Refactor to newer style. * topdown/comparison: Refactor to newer style. * topdown/regex: Refactor to newer style. * topdown/strings: Refactor to newer style. * topdown/time: Refactor to newer style. * topdown/type: Refactor to newer style. * topdown/sets: Refactor to newer style. * topdown/encoding: Refactor to newer style. * topdown/type_name: Refactor to newer style. * topdown/glob: Refactor to newer style. * topdown/parse: Refactor to newer style. * topdown/cidr: Refactor to newer style. This particular file was trickier to refactor than the others so far because the builtins were reused in 1-2 spots, which required renaming/wrapping tricks to get everything working again. Also includes: * builtins: Add function for extracting (Term, error) tuples. * tests: Switch `test.sleep` examples to newer style. * topdown: Use 'operands' over 'args' everywhere. * topdown/builtins: Deprecate functional-style builtins. Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
This commit is contained in:
@@ -106,10 +106,10 @@ func TestProfileCheckExprDuration(t *testing.T) {
|
||||
),
|
||||
})
|
||||
|
||||
topdown.RegisterFunctionalBuiltin1("test.sleep", func(a ast.Value) (ast.Value, error) {
|
||||
d, _ := time.ParseDuration(string(a.(ast.String)))
|
||||
topdown.RegisterBuiltinFunc("test.sleep", func(_ topdown.BuiltinContext, operands []*ast.Term, iter func(*ast.Term) error) error {
|
||||
d, _ := time.ParseDuration(string(operands[0].Value.(ast.String)))
|
||||
time.Sleep(d)
|
||||
return ast.Null{}, nil
|
||||
return iter(ast.NullTerm())
|
||||
})
|
||||
|
||||
module := `package test
|
||||
@@ -152,7 +152,7 @@ func TestProfileCheckExprDuration(t *testing.T) {
|
||||
}
|
||||
|
||||
if fr.Result[0].ExprTimeNs <= time.Duration(50*time.Millisecond).Nanoseconds() {
|
||||
t.Fatalf("Expected eval time is atleast 100 msec but got %v", fr.Result[0].ExprTimeNs)
|
||||
t.Fatalf("Expected eval time is at least 100 msec but got %v", fr.Result[0].ExprTimeNs)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user