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

Commit

Permalink
return a nil message to get skipped in the pipeline (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
jipperinbham authored Feb 6, 2017
1 parent df11d32 commit c52fd88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/adaptor/transformer/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"regexp"
"time"

"github.com/compose/mejson"
"github.com/compose/transporter/pkg/adaptor"
"github.com/compose/transporter/pkg/message"
"github.com/compose/transporter/pkg/message/adaptor/transformer"
"github.com/compose/transporter/pkg/message/data"
"github.com/compose/transporter/pkg/message/ops"
"github.com/compose/transporter/pkg/pipe"
"github.com/compose/mejson"
"github.com/robertkrimen/otto"
_ "github.com/robertkrimen/otto/underscore" // enable underscore
)
Expand Down Expand Up @@ -236,7 +236,7 @@ func (t *Transformer) toMsg(origMsg message.Msg, incoming interface{}) (message.
}
case bool: // skip this doc if we're a bool and we're false
if !newMsg {
op = ops.Noop
return nil, nil
}
default: // something went wrong
return nil, fmt.Errorf("returned doc was not a map[string]interface{}: was %T", newMsg)
Expand Down
5 changes: 4 additions & 1 deletion pkg/adaptor/transformer/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestTransformOne(t *testing.T) {
"we should be able to skip a nil message",
"module.exports=function(doc) { return false }",
message.MustUseAdaptor("transformer").From(ops.Insert, "database.collection", data.Data{"id": bsonID1, "name": "nick"}),
message.MustUseAdaptor("transformer").From(ops.Noop, "database.collection", data.Data{"id": bsonID1, "name": "nick"}),
nil,
false,
},
{
Expand Down Expand Up @@ -138,6 +138,9 @@ func TestTransformOne(t *testing.T) {
}

func isEqual(m1 message.Msg, m2 message.Msg) bool {
if m1 == nil && m2 == nil {
return true
}
if m1.ID() != m2.ID() {
return false
}
Expand Down

0 comments on commit c52fd88

Please sign in to comment.