-
Notifications
You must be signed in to change notification settings - Fork 0
/
int128_test.go
123 lines (103 loc) · 2.91 KB
/
int128_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package eventuate_test
import (
"encoding/json"
"github.com/eventuate-clients/eventuate-client-golang"
"testing"
)
func TestInt128_String(t *testing.T) {
actual := eventuate.Int128([2]uint64{1, 1}).String()
expected := "0000000000000001-0000000000000001"
if expected != actual {
t.Fail()
}
actual = eventuate.Int128([2]uint64{0x15CC85BFDADFF, 0x15CC85BFDADFF}).String()
expected = "00015cc85bfdadff-00015cc85bfdadff"
if expected != actual {
t.Fail()
}
}
func TestInt128FromString(t *testing.T) {
actual := eventuate.Int128FromString("0000000000000001-0000000000000001")
expected := eventuate.Int128([2]uint64{1, 1})
if expected != actual {
t.Fail()
}
actual = eventuate.Int128FromString("00015cc85bfdadff-00015cc85bfdadff")
expected = eventuate.Int128([2]uint64{0x15CC85BFDADFF, 0x15CC85BFDADFF})
if expected != actual {
t.Fail()
}
}
func TestInt128_FirstPart(t *testing.T) {
actual := eventuate.Int128FromString("0000000000000001-0000000000000002").FirstPart()
var expected uint64 = 1
if expected != actual {
t.Fail()
}
actual = eventuate.Int128FromString("00015cc85bfdadff-00015cc85bfdadfe").FirstPart()
expected = 0x15CC85BFDADFF
if expected != actual {
t.Fail()
}
}
func TestInt128_LastPart(t *testing.T) {
actual := eventuate.Int128FromString("0000000000000001-0000000000000002").LastPart()
var expected uint64 = 2
if expected != actual {
t.Fail()
}
actual = eventuate.Int128FromString("00015cc85bfdadff-00015cc85bfdadfe").LastPart()
expected = 0x15CC85BFDADFE
if expected != actual {
t.Fail()
}
}
func TestInt128_MarshalJSON(t *testing.T) {
type EventTypeAndData struct {
EventType string `json:"eventType"`
EventData string `json:"eventData"`
}
type EventIdTypeAndData struct {
EventId eventuate.Int128 `json:"id"`
EventTypeAndData
}
expected := `{"id":"0000015cc85bfdad-0242ac1101190003","eventType":"goodType","eventData":"payload"}`
source := EventIdTypeAndData{
EventId: eventuate.Int128FromString("0000015cc85bfdad-0242ac1101190003"),
EventTypeAndData: EventTypeAndData{
EventType: "goodType",
EventData: "payload"}}
result, err := json.Marshal(source)
actual := string(result)
if err != nil {
t.Fail()
}
if expected != actual {
t.Fail()
}
}
func TestInt128_UnmarshalJSON(t *testing.T) {
type EventTypeAndData struct {
EventType string `json:"eventType"`
EventData string `json:"eventData"`
}
type EventIdTypeAndData struct {
EventId eventuate.Int128 `json:"id"`
EventTypeAndData
}
source := `{"id":"0000015cc85bfdad-0242ac1101190003", "eventType":"goodType", "eventData":"payload"}`
dst := &EventIdTypeAndData{}
err := json.Unmarshal([]byte(source), dst)
expected := EventIdTypeAndData{
EventId: eventuate.Int128FromString("0000015cc85bfdad-0242ac1101190003"),
EventTypeAndData: EventTypeAndData{
EventType: "goodType",
EventData: "payload"}}
actual := *dst
if err != nil {
t.Fail()
}
if expected != actual {
t.Fail()
}
}