MCPcopy Create free account
hub / github.com/olivere/elastic / TestScriptingSource

Function TestScriptingSource

script_test.go:63–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func 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}

Callers

nothing calls this directly

Calls 3

NewScriptInlineFunction · 0.85
FatalfMethod · 0.80
SourceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…