Documentation
¶
Overview ¶
Package test_bootstrap implements the logic for generating Rego test mocks automatically from an OPA bundle and entrypoint list.
Index ¶
- func ASTObjectsFromRefs(refs []ast.Ref, defaultLeafValue *ast.Term) (*ast.Term, *ast.Term, error)
- func GetCustomAnnotationsForRefs(compiler *ast.Compiler) (map[string][]*ast.AnnotationsRef, error)
- func GetFileLocationForRuleRef(ruleRef ast.Ref, compiler *ast.Compiler) string
- func GetInputFromRuleDeps(rule *ast.Rule, compiler *ast.Compiler) (*ast.Term, error)
- func GetPackageForRuleRef(ruleRef ast.Ref, compiler *ast.Compiler) string
- func GetRuleCustomAnnotationWithKey(key string, entrypoint ast.Ref, compiler *ast.Compiler) (*ast.AnnotationsRef, error)
- func GetTestNamesToCustomAnnotations(compiler *ast.Compiler) (map[string][]*ast.AnnotationsRef, error)
- func LoadPolicies(dataPaths []string, ignores []string) (*ast.Compiler, error)
- func RefPtrToQuery(rp string) string
- func StartBootstrap(_ context.Context, opt ...Opt) error
- func StartNew(_ context.Context, opt ...Opt) error
- func TestcasesForRule(testName string, rule *ast.Rule, compiler *ast.Compiler) (string, error)
- func TestcasesFromRef(ruleRef ast.Ref, generatedNames map[string]string, compiler *ast.Compiler) (string, error)
- func VivifyTree(tree *edittree.EditTree, ref ast.Ref)
- type Opt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ASTObjectsFromRefs ¶
Builds Rego AST objects, based on the refs provided to it. Note(philip): I wanted to do this without needing the EditTree structure from OPA's internals, but it certainly makes some aspects of the structure generation here very straightforward.
func GetCustomAnnotationsForRefs ¶
Returns a map of targeted rule paths and their accompanying annotations refs.
func GetFileLocationForRuleRef ¶
Note(philip): This selects the first non-nil file location found for the rule ref. In cases where multiple files may match the ref, this results in one of those files being selected *arbitrarily*. I'm not sure how to make this less awful, but we can at least log where things will land.
func GetInputFromRuleDeps ¶
This function plugs in a rule, and attempts to extract a useful input object for the testcase.
func GetPackageForRuleRef ¶
Note(philip): This selects the first non-nil file package found for the rule.
func GetTestNamesToCustomAnnotations ¶
func GetTestNamesToCustomAnnotations(compiler *ast.Compiler) (map[string][]*ast.AnnotationsRef, error)
Returns a map of targeted rule paths corresponding to the `test-bootstrap-name` custom annotation.
func LoadPolicies ¶
Loads up all of the specified Rego sources. Returns an ast.Compiler instance.
func RefPtrToQuery ¶
func TestcasesForRule ¶
func TestcasesFromRef ¶
func TestcasesFromRef(ruleRef ast.Ref, generatedNames map[string]string, compiler *ast.Compiler) (string, error)
This function is the place where all the testcase generation pieces are assembled. It takes a virtual document reference, and then discovers all rules that apply to it. Each rule is then individually analyzed, and a testcase is generated for it using the testcase templates. The collected set of testcases is then returned as a string.