-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtesthelper_test.go
54 lines (47 loc) · 1.62 KB
/
testhelper_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
package zkafka
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/zillow/zfmt"
)
func Test_getFakeMessage(t *testing.T) {
defer recoverThenFail(t)
msg := getFakeMessage("key", "value", &zfmt.JSONFormatter{}, nil)
expectedMessage := Message{
Key: "key",
value: []byte("\"value\""),
}
require.Equal(t, expectedMessage.Key, msg.Key, "Expected generated zkafka.Message to use key from arg")
require.Equal(t, string(expectedMessage.value), string(msg.value), "Expected generated zkafka.Message to use value from arg")
}
func TestGetFakeMessageFromFake(t *testing.T) {
defer recoverThenFail(t)
fmtr := &zfmt.JSONFormatter{}
val, err := fmtr.Marshall("value")
require.NoError(t, err)
msg := GetMsgFromFake(&FakeMessage{
Key: ptr("key"),
Value: val,
Fmt: fmtr,
})
expectedMessage := Message{
Key: "key",
value: []byte("\"value\""),
}
require.Equal(t, expectedMessage.Key, msg.Key, "Expected generated zkafka.Message to use key from arg")
require.Equal(t, string(expectedMessage.value), string(msg.value), "Expected generated zkafka.Message to use value from arg")
}
func TestMsgFromFake_WhenMarshallError(t *testing.T) {
// pass in some invalid object for marshalling
msg := GetMsgFromFake(&FakeMessage{
Key: ptr("key"),
ValueData: make(chan int),
Fmt: &zfmt.JSONFormatter{},
})
expectedMessage := Message{
Key: "key",
value: nil,
}
require.Equal(t, expectedMessage.Key, msg.Key, "Expected generated zkafka.Message to use key from arg")
require.Equal(t, string(expectedMessage.value), string(msg.value), "Expected generated zkafka.Message to use value from arg")
}