(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func TestInlineIncludes(t *testing.T) { |
| 60 | |
| 61 | t1 := time.Now() |
| 62 | |
| 63 | readers := []expr.ContextReader{ |
| 64 | datasource.NewContextMap(map[string]interface{}{ |
| 65 | "name": "bob", |
| 66 | "city": "Peoria, IL", |
| 67 | "zip": 5, |
| 68 | "signedup": t1, |
| 69 | "lastevent": map[string]time.Time{"signedup": t1}, |
| 70 | "last.event": map[string]time.Time{"has.period": t1}, |
| 71 | }, true), |
| 72 | } |
| 73 | |
| 74 | nc := datasource.NewNestedContextReader(readers, time.Now()) |
| 75 | includerCtx := newIncluderCtx(nc, ` |
| 76 | FILTER name == "Yoda" ALIAS is_yoda_true; |
| 77 | FILTER AND ( |
| 78 | planet == "Dagobah" |
| 79 | INCLUDE is_yoda_true |
| 80 | ) ALIAS nested_includes_yoda; |
| 81 | `) |
| 82 | |
| 83 | tests := []incTest{ |
| 84 | { |
| 85 | in: `lastvisit_ts < "now-1d"`, |
| 86 | out: `lastvisit_ts < "now-1d"`, |
| 87 | }, |
| 88 | { |
| 89 | in: `AND ( lastvisit_ts < "now-1d", INCLUDE is_yoda_true )`, |
| 90 | out: `AND ( lastvisit_ts < "now-1d", name == "Yoda" )`, |
| 91 | }, |
| 92 | { |
| 93 | in: `AND ( lastvisit_ts < "now-2d", NOT INCLUDE is_yoda_true )`, |
| 94 | out: `AND ( lastvisit_ts < "now-2d", NOT (name == "Yoda") )`, |
| 95 | }, |
| 96 | { |
| 97 | in: `AND ( lastvisit_ts < "now-3d", NOT INCLUDE nested_includes_yoda )`, |
| 98 | out: `AND ( lastvisit_ts < "now-3d", NOT AND ( planet == "Dagobah", (name == "Yoda") ) )`, |
| 99 | }, |
| 100 | } |
| 101 | tests = []incTest{ |
| 102 | { |
| 103 | in: `AND ( lastvisit_ts < "now-3d", NOT INCLUDE nested_includes_yoda )`, |
| 104 | out: `AND ( lastvisit_ts < "now-3d", NOT AND ( planet == "Dagobah", name == "Yoda" ) )`, |
| 105 | }, |
| 106 | } |
| 107 | for _, tc := range tests { |
| 108 | n := expr.MustParse(tc.in) |
| 109 | out, err := expr.InlineIncludes(includerCtx, n) |
| 110 | assert.Equal(t, nil, err) |
| 111 | assert.NotEqual(t, nil, out) |
| 112 | if out != nil { |
| 113 | assert.Equal(t, tc.out, out.String()) |
| 114 | } |
| 115 | } |
| 116 |
nothing calls this directly
no test coverage detected