forked from italolelis/outboxer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
outbox_message_test.go
80 lines (64 loc) · 1.56 KB
/
outbox_message_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
68
69
70
71
72
73
74
75
76
77
78
79
80
package outboxer_test
import (
"testing"
"github.com/italolelis/outboxer"
)
func TestOutboxMessage(t *testing.T) {
t.Parallel()
tests := []struct {
scenario string
function func(*testing.T)
}{
{
"check if DynamicValues Scan works for message",
testDynamicValuesScan,
},
{
"check if DynamicValues Value works for message",
testDynamicValuesValue,
},
}
for _, test := range tests {
test := test
t.Run(test.scenario, func(t *testing.T) {
test.function(t)
})
}
}
func testDynamicValuesScan(t *testing.T) {
dv := outboxer.DynamicValues{}
if err := dv.Scan([]byte(`{"key": "value"}`)); err != nil {
t.Fatalf("failed to scan DynamicValues value: %s", err)
}
if _, ok := dv["key"]; !ok {
t.Fatal("failed to scan DynamicValue json")
}
if dv["key"] != "value" {
t.Fatal("a string `value` was expected")
}
if err := dv.Scan([]byte(``)); err == nil {
t.Fatal("an error was expected when parsing an empty slice of bytes")
}
if err := dv.Scan(nil); err != nil {
t.Fatal("no error was expected when scanning a nil value")
}
}
func testDynamicValuesValue(t *testing.T) {
dv := outboxer.DynamicValues{}
dv["key"] = "value"
v, err := dv.Value()
if err != nil {
t.Fatalf("failed to get driver.Value from DynamicValues: %s", err)
}
if v == nil {
t.Fatalf("driver.Value is not supposed to be nil: %s", err)
}
dv = outboxer.DynamicValues{}
v, err = dv.Value()
if err != nil {
t.Fatalf("failed to get driver.Value from DynamicValues: %s", err)
}
if v != nil {
t.Fatalf("driver.Value is supposed to be nil: %s", err)
}
}