@@ -139,3 +139,47 @@ func TestKafka_Start(t *testing.T) {
139139 db .GetClient ().DeleteByQuery (esIndex ).Query (elastic.MatchAllQuery {}).Do (context .Background ())
140140 db .CloseClient ()
141141}
142+
143+ func TestKafka_Start_WithNilValue (t * testing.T ) {
144+ signals := make (chan os.Signal , 1 )
145+ notifications := make (chan Notification , 1 )
146+ go k .Start (signals , notifications )
147+ config := sarama .NewConfig ()
148+ config .Producer .Return .Successes = true
149+ config .Producer .MaxMessageBytes = 20 * 1024 * 1024 // 20mb
150+ config .Producer .Flush .Frequency = 1 * time .Millisecond
151+ config .Version = sarama .V0_10_0_0 // This version is the same as in production
152+ <- notifications
153+ producer , err := fixtures .NewProducer ("localhost:9092" , config , schemaRegistry )
154+ expectedTimestamp := time .Now ().UnixNano () / int64 (time .Millisecond )
155+ rec := fixtures .NewEmptyFixtureRecord ()
156+ var msg * sarama.ProducerMessage
157+ if assert .NoError (t , err ) {
158+
159+ err = producer .Publish (rec )
160+ if assert .NoError (t , err ) {
161+ msg = <- producer .GetSuccesses ()
162+ } else {
163+ fmt .Println (err .Error ())
164+ }
165+ }
166+ <- notifications
167+ esIndex := fmt .Sprintf ("%s-%s" , msg .Topic , time .Now ().Format ("2006-01-02" ))
168+ esId := fmt .Sprintf ("%d:%d" , msg .Partition , msg .Offset )
169+ _ , err = db .GetClient ().Refresh (esIndex ).Do (context .Background ())
170+ if assert .NoError (t , err ) {
171+ res , err := db .GetClient ().Get ().Index (esIndex ).Id (esId ).Do (context .Background ())
172+ var r fixtures.FixtureRecord
173+ if assert .NoError (t , err ) {
174+ assert .True (t , res .Found )
175+ err = json .Unmarshal (res .Source , & r )
176+ if assert .NoError (t , err ) {
177+ assert .Equal (t , rec .Id , r .Id )
178+ assert .InDelta (t , expectedTimestamp , r .Timestamp , 5000.0 )
179+ }
180+ }
181+ signals <- os .Interrupt
182+ }
183+ db .GetClient ().DeleteByQuery (esIndex ).Query (elastic.MatchAllQuery {}).Do (context .Background ())
184+ db .CloseClient ()
185+ }
0 commit comments