-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upgrade Roast to v0.6.0 Roast now also on OPA 1.0, and v0.6.0 brings slightly faster serialization of terms as well. Included in this PR too some minor fixes that don't deserve their own PR. Signed-off-by: Anders Eknert <anders@styra.com> * builtins/test: Use new go range loops Address linter issue Signed-off-by: Charlie Egan <charlie@styra.com> --------- Signed-off-by: Anders Eknert <anders@styra.com> Signed-off-by: Charlie Egan <charlie@styra.com> Co-authored-by: Charlie Egan <charlie@styra.com>
- Loading branch information
1 parent
0aedf5c
commit 954df8c
Showing
6 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package builtins_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/open-policy-agent/opa/v1/ast" | ||
"github.com/open-policy-agent/opa/v1/rego" | ||
|
||
"github.com/styrainc/regal/pkg/builtins" | ||
) | ||
|
||
// Can't be much faster than this.. | ||
// BenchmarkRegalLast-10 163252460 7.218 ns/op 0 B/op 0 allocs/op | ||
// ... | ||
func BenchmarkRegalLast(b *testing.B) { | ||
bctx := rego.BuiltinContext{} | ||
ta, tb, tc := ast.StringTerm("a"), ast.StringTerm("b"), ast.StringTerm("c") | ||
arr := ast.ArrayTerm(ta, tb, tc) | ||
|
||
var res *ast.Term | ||
|
||
for range b.N { | ||
var err error | ||
|
||
res, err = builtins.RegalLast(bctx, arr) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
|
||
if res.Value.Compare(tc.Value) != 0 { | ||
b.Fatalf("expected c, got %v", res) | ||
} | ||
} | ||
|
||
// Likewise for the empty array case. | ||
// BenchmarkRegalLastEmptyArr-10 160589398 7.498 ns/op 0 B/op 0 allocs/op | ||
// ... | ||
func BenchmarkRegalLastEmptyArr(b *testing.B) { | ||
bctx := rego.BuiltinContext{} | ||
arr := ast.ArrayTerm() | ||
|
||
var err error | ||
|
||
for range b.N { | ||
_, err = builtins.RegalLast(bctx, arr) | ||
} | ||
|
||
if err == nil { | ||
b.Fatal("expected error, got nil") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters