PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/es/term_test.go

https://code.google.com/p/esapi-go/
Go | 46 lines | 34 code | 9 blank | 3 comment | 10 complexity | e9383ed0512d60ece900fa12edeb64d6 MD5 | raw file
 1package es
 2
 3import (
 4	"testing"
 5)
 6
 7func TestTerm(t *testing.T) {
 8	c := NewConn("http://localhost:9200")
 9	i := c.Open("agenda", "person")
10	err := i.Write("", `{"name":"Andre", "age":25, "likes":["programming", "rpg", "game development"]}`)
11	if err != nil {
12		t.Fatalf("Should have wrote to the index. But got error: %q", err)
13	}
14
15	ret, err := i.Term("name", "Andre")
16
17	if err != nil {
18		t.Fatalf("Unexpected error: %q", err)
19	}
20
21	for id := range ret {
22		t.Errorf("Id: %q", id)
23	}
24}
25
26func TestTermArray(t *testing.T) {
27	c := NewConn("http://localhost:9200")
28	i := c.Open("agenda", "person")
29	err := i.Write("", `{"name":"Andre", "age":25, "likes":["programming", "rpg", "game development"]}`)
30	if err != nil {
31		t.Fatalf("Should have wrote to the index. But got error: %q", err)
32	}
33
34	// note that in this query
35	// the field is a array
36	// but the value should be returned anyway
37	ret, err := i.Term("likes", "rpg")
38
39	if err != nil {
40		t.Fatalf("Unexpected error: %q", err)
41	}
42
43	for id := range ret {
44		t.Errorf("Id: %q", id)
45	}
46}