-
Notifications
You must be signed in to change notification settings - Fork 1
/
message_test.go
74 lines (67 loc) · 1.8 KB
/
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
package main
import (
"fmt"
"testing"
)
func TestMessageWithEnvelope_Operations(t *testing.T) {
for _, test := range []struct {
operation string
expectCreate bool
expectUpdate bool
expectDelete bool
}{
{"None", false, false, false},
{"CREATE", true, false, false},
{"create", false, false, false},
{"Create", false, false, false},
{"UPDATE", false, true, false},
{"uPdATe", false, false, false},
{"upDATE", false, false, false},
{"DELETE", false, false, true},
{"delete", false, false, false},
{"DEELETE", false, false, false},
} {
t.Run("When Operation is "+test.operation, func(t *testing.T) {
mwe := MessageWithEnvelope{
Operation: test.operation,
}
t.Run(fmt.Sprintf("Create() should return %v", test.expectCreate), func(t *testing.T) {
rcvd := mwe.Create()
if test.expectCreate != rcvd {
t.Errorf("Expected %v, received %v", test.expectCreate, rcvd)
}
})
t.Run(fmt.Sprintf("Update() should return %v", test.expectUpdate), func(t *testing.T) {
rcvd := mwe.Update()
if test.expectUpdate != rcvd {
t.Errorf("Expected %v, received %v", test.expectUpdate, rcvd)
}
})
t.Run(fmt.Sprintf("Delete() should return %v", test.expectDelete), func(t *testing.T) {
rcvd := mwe.Delete()
if test.expectDelete != rcvd {
t.Errorf("Expected %v, received %v", test.expectDelete, rcvd)
}
})
})
}
}
func TestParseMessage(t *testing.T) {
msg := `{
"operation": "CREATE",
"provenance": "wordpress",
"version": "1.0.0",
"message": {
"slug": "a-post",
"title": "This is my first post<3",
"author": "a.n. other",
"date": "2019-04-20T17:13:06Z",
"body": "Hello, world!"
}
}
`
_, err := ParseMessage([]byte(msg))
if err != nil {
t.Errorf("unexpected error: %+v", err)
}
}