forked from compose/transporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prettify_test.go
67 lines (60 loc) · 1.58 KB
/
prettify_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package pretty
import (
"reflect"
"testing"
"time"
"github.com/compose/transporter/function"
_ "github.com/compose/transporter/log"
"github.com/compose/transporter/message"
"github.com/compose/transporter/message/ops"
bson "gopkg.in/mgo.v2/bson"
)
var initTests = []struct {
in map[string]interface{}
expect *prettify
}{
{map[string]interface{}{}, defaultPrettifier},
}
func TestInit(t *testing.T) {
for _, it := range initTests {
a, err := function.GetFunction("pretty", it.in)
if err != nil {
t.Fatalf("unexpected GetFunction() error, %s", err)
}
if !reflect.DeepEqual(a, it.expect) {
t.Errorf("misconfigured Function, expected %+v, got %+v", it.expect, a)
}
}
}
var prettyTests = []struct {
p *prettify
data map[string]interface{}
}{
{
defaultPrettifier,
map[string]interface{}{"_id": "blah", "type": "good"},
},
{
defaultPrettifier,
map[string]interface{}{"_id": "blah", "type": "good", "name": "hello"},
},
{
defaultPrettifier,
map[string]interface{}{"_id": bson.NewObjectId(), "hello": "world", "ts": bson.MongoTimestamp(time.Now().Unix() << 32)},
},
{
&prettify{Spaces: 0},
map[string]interface{}{"_id": bson.NewObjectId(), "hello": "world", "ts": bson.MongoTimestamp(time.Now().Unix() << 32)},
},
}
func TestApply(t *testing.T) {
for _, pt := range prettyTests {
msg, err := pt.p.Apply(message.From(ops.Insert, "test", pt.data))
if err != nil {
t.Errorf("unexpected error, got %s", err)
}
if !reflect.DeepEqual(msg.Data().AsMap(), pt.data) {
t.Errorf("wrong message, expected %+v, got %+v", pt.data, msg.Data().AsMap())
}
}
}