Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
add a test to ensure message copying works and _id is not touched
Browse files Browse the repository at this point in the history
  • Loading branch information
jipperinbham committed Jan 24, 2017
1 parent 7d8b223 commit c239adb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/adaptor/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (e *Elasticsearch) Stop() error {

func (e *Elasticsearch) applyOp(msg message.Msg) (message.Msg, error) {
_, msgColl, _ := message.SplitNamespace(msg)
var msgCopy map[string]interface{}
msgCopy := make(map[string]interface{})
// Copy from the original map to the target map
for key, value := range msg.Data() {
msgCopy[key] = value
Expand Down
8 changes: 7 additions & 1 deletion pkg/adaptor/elasticsearch/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,17 @@ func TestListen(t *testing.T) {
}
go e.Listen()

sourcePipe.Send(message.From(ops.Insert, "source.test", map[string]interface{}{"hello": "world"}))
mockMsg := map[string]interface{}{"_id": "NO_TOUCHING", "hello": "world"}
sourcePipe.Send(message.From(ops.Insert, "source.test", mockMsg))

e.Stop()
if mockWriter.msgCount != 1 {
t.Errorf("unexpected message count, expected %d, got %d\n", 1, mockWriter.msgCount)
}

if _, ok := mockMsg["_id"]; !ok {
t.Error("_id should still exist in mockMsg but does not")
}
}

type MockWriter struct {
Expand All @@ -218,6 +223,7 @@ type MockWriter struct {

func (w *MockWriter) Write(msg message.Msg) func(client.Session) error {
return func(s client.Session) error {
msg.Data().Delete("_id")
w.msgCount++
return nil
}
Expand Down

0 comments on commit c239adb

Please sign in to comment.