forked from getlantern/marionette
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell_test.go
101 lines (88 loc) · 2.08 KB
/
cell_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
package marionette_test
import (
"reflect"
"testing"
"github.com/redjack/marionette"
)
func TestCell_Compare(t *testing.T) {
cell := &marionette.Cell{SequenceID: 2}
if cmp := cell.Compare(&marionette.Cell{SequenceID: 1}); cmp != 1 {
t.Fatalf("unexpected comparison: %d", cmp)
}
if cmp := cell.Compare(&marionette.Cell{SequenceID: 2}); cmp != 0 {
t.Fatalf("unexpected comparison: %d", cmp)
}
if cmp := cell.Compare(&marionette.Cell{SequenceID: 3}); cmp != -1 {
t.Fatalf("unexpected comparison: %d", cmp)
}
}
func TestCell_Equal(t *testing.T) {
cell := &marionette.Cell{
Type: marionette.CellTypeNormal,
Payload: []byte("foo"),
SequenceID: 1,
StreamID: 3,
UUID: 4,
InstanceID: 5,
}
t.Run("OK", func(t *testing.T) {
other := *cell
if !cell.Equal(&other) {
t.Fatal("expected equality")
}
})
t.Run("PayloadMismatch", func(t *testing.T) {
other := *cell
other.Payload = []byte("bar")
if cell.Equal(&other) {
t.Fatal("expected inequality")
}
})
t.Run("StreamIDMismatch", func(t *testing.T) {
other := *cell
other.StreamID = 100
if cell.Equal(&other) {
t.Fatal("expected inequality")
}
})
t.Run("UUIDMismatch", func(t *testing.T) {
other := *cell
other.UUID = 100
if cell.Equal(&other) {
t.Fatal("expected inequality")
}
})
t.Run("InstanceIDMismatch", func(t *testing.T) {
other := *cell
other.InstanceID = 100
if cell.Equal(&other) {
t.Fatal("expected inequality")
}
})
t.Run("SequenceIDMismatch", func(t *testing.T) {
other := *cell
other.SequenceID = 100
if cell.Equal(&other) {
t.Fatal("expected inequality")
}
})
}
func TestCell_MarshalBinary(t *testing.T) {
cell := &marionette.Cell{
Type: marionette.CellTypeNormal,
Payload: []byte("foo"),
Length: 28,
SequenceID: 1,
StreamID: 3,
UUID: 4,
InstanceID: 5,
}
var other marionette.Cell
if buf, err := cell.MarshalBinary(); err != nil {
t.Fatal(err)
} else if err := other.UnmarshalBinary(buf); err != nil {
t.Fatal(err)
} else if !reflect.DeepEqual(cell, &other) {
t.Fatalf("mismatch: %#v", &other)
}
}