MCPcopy Index your code
hub / github.com/coder/coder / TestRegoQueries

Function TestRegoQueries

coderd/rbac/regosql/compile_test.go:16–374  ·  view source on GitHub ↗

TestRegoQueriesNoVariables handles cases without variables. These should be very simple and straight forward.

(t *testing.T)

Source from the content-addressed store, hash-verified

14// TestRegoQueriesNoVariables handles cases without variables. These should be
15// very simple and straight forward.
16func TestRegoQueries(t *testing.T) {
17 t.Parallel()
18
19 p := func(v string) string {
20 return "(" + v + ")"
21 }
22
23 testCases := []struct {
24 Name string
25 Queries []string
26 ExpectedSQL string
27 ExpectError bool
28 ExpectedSQLGenError bool
29
30 VariableConverter sqltypes.VariableMatcher
31 }{
32 {
33 Name: "Empty",
34 Queries: []string{``},
35 ExpectedSQL: "true",
36 },
37 {
38 Name: "True",
39 Queries: []string{`true`},
40 ExpectedSQL: "true",
41 },
42 {
43 Name: "False",
44 Queries: []string{`false`},
45 ExpectedSQL: "false",
46 },
47 {
48 Name: "MultipleBool",
49 Queries: []string{"true", "false"},
50 ExpectedSQL: "(true OR false)",
51 },
52 {
53 Name: "Numbers",
54 Queries: []string{
55 "(1 != 2) = true",
56 "5 == 5",
57 },
58 ExpectedSQL: p("((1 != 2) = true) OR (5 = 5)"),
59 },
60 // Variables
61 {
62 // Always return a constant string for all variables.
63 Name: "V_Basic",
64 Queries: []string{
65 `input.x = "hello_world"`,
66 },
67 ExpectedSQL: p("only_var = 'hello_world'"),
68 VariableConverter: sqltypes.NewVariableConverter().RegisterMatcher(
69 sqltypes.StringVarMatcher("only_var", []string{
70 "input", "x",
71 }),
72 ),
73 },

Callers

nothing calls this directly

Calls 14

NewVariableConverterFunction · 0.92
StringVarMatcherFunction · 0.92
DefaultVariableConverterFunction · 0.92
NoACLConverterFunction · 0.92
WorkspaceConverterFunction · 0.92
ChatConverterFunction · 0.92
TemplateConverterFunction · 0.92
UserConverterFunction · 0.92
AuditLogConverterFunction · 0.92
ConnectionLogConverterFunction · 0.92
partialQueriesFunction · 0.85
requireConvertFunction · 0.85

Tested by

no test coverage detected