Test to verify fields in a document can be extracted from a struct
This commit is contained in:
parent
bfa1530af9
commit
9b27ec1889
67
goes_test.go
67
goes_test.go
@ -321,6 +321,73 @@ func (s *GoesTestSuite) TestStats(c *C) {
|
|||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *GoesTestSuite) TestIndexWithFieldsInStruct(c *C) {
|
||||||
|
indexName := "testindexwithfieldsinstruct"
|
||||||
|
docType := "tweet"
|
||||||
|
docId := "1234"
|
||||||
|
|
||||||
|
conn := NewConnection(ES_HOST, ES_PORT)
|
||||||
|
// just in case
|
||||||
|
conn.DeleteIndex(indexName)
|
||||||
|
|
||||||
|
_, err := conn.CreateIndex(indexName, map[string]interface{}{})
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
defer conn.DeleteIndex(indexName)
|
||||||
|
|
||||||
|
d := Document{
|
||||||
|
Index: indexName,
|
||||||
|
Type: docType,
|
||||||
|
Id: docId,
|
||||||
|
Fields: struct {
|
||||||
|
user string
|
||||||
|
message string
|
||||||
|
}{
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
extraArgs := make(url.Values, 1)
|
||||||
|
extraArgs.Set("ttl", "86400000")
|
||||||
|
response, err := conn.Index(d, extraArgs)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
expectedResponse := Response{
|
||||||
|
Index: indexName,
|
||||||
|
Id: docId,
|
||||||
|
Type: docType,
|
||||||
|
Version: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Assert(response, DeepEquals, expectedResponse)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GoesTestSuite) TestIndexWithFieldsNotInMapOrStruct(c *C) {
|
||||||
|
indexName := "testindexwithfieldsnotinmaporstruct"
|
||||||
|
docType := "tweet"
|
||||||
|
docId := "1234"
|
||||||
|
|
||||||
|
conn := NewConnection(ES_HOST, ES_PORT)
|
||||||
|
// just in case
|
||||||
|
conn.DeleteIndex(indexName)
|
||||||
|
|
||||||
|
_, err := conn.CreateIndex(indexName, map[string]interface{}{})
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
defer conn.DeleteIndex(indexName)
|
||||||
|
|
||||||
|
d := Document{
|
||||||
|
Index: indexName,
|
||||||
|
Type: docType,
|
||||||
|
Id: docId,
|
||||||
|
Fields: "test",
|
||||||
|
}
|
||||||
|
|
||||||
|
extraArgs := make(url.Values, 1)
|
||||||
|
extraArgs.Set("ttl", "86400000")
|
||||||
|
_, err = conn.Index(d, extraArgs)
|
||||||
|
c.Assert(err, Not(IsNil))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *GoesTestSuite) TestIndexIdDefined(c *C) {
|
func (s *GoesTestSuite) TestIndexIdDefined(c *C) {
|
||||||
indexName := "testindexiddefined"
|
indexName := "testindexiddefined"
|
||||||
docType := "tweet"
|
docType := "tweet"
|
||||||
|
Loading…
Reference in New Issue
Block a user