forked from olivere/elastic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_template_test.go
62 lines (56 loc) · 1.33 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
52
53
54
55
56
57
58
59
60
61
62
// 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)
tmpl := `{
"template":"elastic-test*",
"settings":{
"number_of_shards":1,
"number_of_replicas":0
},
"mappings":{
"tweet":{
"properties":{
"tags":{
"type":"string"
},
"location":{
"type":"geo_point"
},
"suggest_field":{
"type":"completion",
"payloads":true
}
}
}
}
}`
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)
}
}