From 9b27ec188919deefe4e0a6593782bb009fcec985 Mon Sep 17 00:00:00 2001 From: Amadeo Casas Date: Sun, 17 Aug 2014 13:25:25 -0700 Subject: [PATCH] Test to verify fields in a document can be extracted from a struct --- goes_test.go | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) 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"