Skip to content

doc: update builtin function examples for v1 (#7514) #7515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/content/contrib-adding-builtin-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:

Expand All @@ -117,7 +117,7 @@ cases:
- |
package test

p := repeated {
p := repeated if {
repeated := repeat(input.str, input.count)
}
input: {"str": "Foo", "count": 3}
Expand All @@ -129,7 +129,7 @@ cases:
- |
package test

p := repeated {
p := repeated if {
repeated := repeat(input.str, input.count)
}
input: { "str": "Foo", "count": -3 }
Expand All @@ -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.
Expand Down
Loading