-
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.
rules: Add InputFromTextWithOptions for go users
This creates a helper function that creates an `Input` given a module as a string in a given version of Rego. This is being added for the rego-playground primarily. Signed-off-by: Charlie Egan <charlie@styra.com>
- Loading branch information
1 parent
f61f52b
commit d855fce
Showing
2 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package rules | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/open-policy-agent/opa/ast" | ||
) | ||
|
||
func TestInputFromTextWithOptions(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := map[string]struct { | ||
Module string | ||
RegoVersion ast.RegoVersion | ||
}{ | ||
"regov1": { | ||
Module: `package test | ||
p if { true }`, | ||
RegoVersion: ast.RegoV1, | ||
}, | ||
"regov0": { | ||
Module: `package test | ||
p { true }`, | ||
RegoVersion: ast.RegoV0, | ||
}, | ||
} | ||
|
||
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
_, err := InputFromTextWithOptions("p.rego", tc.Module, ast.ParserOptions{ | ||
RegoVersion: tc.RegoVersion, | ||
}) | ||
if err != nil { | ||
t.Errorf("Expected no error, got %v", err) | ||
} | ||
}) | ||
} | ||
} |