From ad7a73585ea8c6251dda2befd4ce463850f5266b Mon Sep 17 00:00:00 2001 From: Rob Myers <1243316+robmyersrobmyers@users.noreply.github.com> Date: Mon, 14 Apr 2025 08:58:07 -0400 Subject: [PATCH] doc: update builtin function examples for v1 (#7514) Signed-off-by: Rob Myers <1243316+robmyersrobmyers@users.noreply.github.com> --- docs/content/contrib-adding-builtin-functions.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/content/contrib-adding-builtin-functions.md b/docs/content/contrib-adding-builtin-functions.md index 1d7b6eac41..5e5316c55d 100644 --- a/docs/content/contrib-adding-builtin-functions.md +++ b/docs/content/contrib-adding-builtin-functions.md @@ -69,8 +69,8 @@ import ( "fmt" "strings" - "github.com/open-policy-agent/opa/ast" - "github.com/open-policy-agent/opa/topdown/builtins" + "github.com/open-policy-agent/opa/v1/ast" + "github.com/open-policy-agent/opa/v1/topdown/builtins" ) // implements topdown.BuiltinFunc @@ -105,7 +105,7 @@ The call to `RegisterBuiltinFunc(...)` in `init()` adds the built-in function to ### Test All built-in function implementations must include a test suite. -Test cases for built-in functions are written in YAML and located under `test/cases/testdata`. +Test cases for built-in functions are written in YAML and located under `test/cases/testdata/v1`. We create two new test cases (one positive, expecting a string output; and one negative, expecting an error) for our built-in function: @@ -117,7 +117,7 @@ cases: - | package test - p := repeated { + p := repeated if { repeated := repeat(input.str, input.count) } input: {"str": "Foo", "count": 3} @@ -129,7 +129,7 @@ cases: - | package test - p := repeated { + p := repeated if { repeated := repeat(input.str, input.count) } input: { "str": "Foo", "count": -3 } @@ -138,7 +138,7 @@ cases: want_error: 'repeat: count must be a positive integer' ``` -The above test cases can be run separate from all other tests through: `go test ./topdown -v -run 'TestRego/repeat'` +The above test cases can be run separate from all other tests through: `go test ./topdown -v -run 'TestRego/v1/repeat'` See [test/cases/testdata/helloworld](https://github.com/open-policy-agent/opa/blob/main/test/cases/testdata/helloworld) for a more detailed example of how to implement tests for your built-in functions.