diff --git a/goes_test.go b/goes_test.go index ce27af3..f1bce23 100644 --- a/goes_test.go +++ b/goes_test.go @@ -321,6 +321,73 @@ func (s *GoesTestSuite) TestStats(c *C) { 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) { indexName := "testindexiddefined" docType := "tweet"