(t *testing.T)
| 61 | } |
| 62 | |
| 63 | func TestScriptingSource(t *testing.T) { |
| 64 | tests := []struct { |
| 65 | Input string |
| 66 | Source string |
| 67 | }{ |
| 68 | { |
| 69 | Input: ``, |
| 70 | Source: `{"source":""}`, |
| 71 | }, |
| 72 | { |
| 73 | Input: `doc['field'].value * factor`, |
| 74 | Source: `{"source":"doc['field'].value * factor"}`, |
| 75 | }, |
| 76 | { |
| 77 | Input: `"doc['field'].value * factor"`, |
| 78 | Source: `{"source":"doc['field'].value * factor"}`, |
| 79 | }, |
| 80 | { |
| 81 | Input: `{"bool":{"filter":{"term":{"field1":"f"}}}}`, |
| 82 | Source: `{"source":{"bool":{"filter":{"term":{"field1":"f"}}}}}`, |
| 83 | }, |
| 84 | } |
| 85 | for _, tt := range tests { |
| 86 | b := NewScriptInline(tt.Input) |
| 87 | src, err := b.Source() |
| 88 | if err != nil { |
| 89 | t.Fatalf("unable to generate source for %s: %v", tt.Input, err) |
| 90 | } |
| 91 | out, err := json.Marshal(src) |
| 92 | if err != nil { |
| 93 | t.Fatalf("unable to generate JSON for %s: %v", tt.Input, err) |
| 94 | } |
| 95 | if want, have := tt.Source, string(out); want != have { |
| 96 | t.Fatalf("Input=%q: want %s, have %s", tt.Input, want, have) |
| 97 | } |
| 98 | } |
| 99 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…