TestRegoQueriesNoVariables handles cases without variables. These should be very simple and straight forward.
(t *testing.T)
| 14 | // TestRegoQueriesNoVariables handles cases without variables. These should be |
| 15 | // very simple and straight forward. |
| 16 | func 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 | }, |
nothing calls this directly
no test coverage detected