forked from olivere/elastic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_template_test.go
51 lines (45 loc) · 1.26 KB
/
get_template_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
// Use of this source code is governed by a MIT-license.
// See http://olivere.mit-license.org/license.txt for details.
package elastic
import (
"testing"
)
func TestGetPutDeleteTemplate(t *testing.T) {
client := setupTestClientAndCreateIndex(t)
// This is a search template, not an index template!
tmpl := `{
"template": {
"query" : { "term" : { "{{my_field}}" : "{{my_value}}" } },
"size" : "{{my_size}}"
},
"params":{
"my_field" : "user",
"my_value" : "olivere",
"my_size" : 5
}
}`
putres, err := client.PutTemplate().Id("elastic-template").BodyString(tmpl).Do()
if err != nil {
t.Fatalf("expected no error; got: %v", err)
}
if putres == nil {
t.Fatalf("expected response; got: %v", putres)
}
if !putres.Created {
t.Fatalf("expected template to be created; got: %v", putres.Created)
}
// Always delete template
defer client.DeleteTemplate().Id("elastic-template").Do()
// Get template
getres, err := client.GetTemplate().Id("elastic-template").Do()
if err != nil {
t.Fatalf("expected no error; got: %v", err)
}
if getres == nil {
t.Fatalf("expected response; got: %v", getres)
}
if getres.Template == "" {
t.Errorf("expected template %q; got: %q", tmpl, getres.Template)
}
}