-
Notifications
You must be signed in to change notification settings - Fork 48
/
ematch_container_test.go
67 lines (59 loc) · 1.46 KB
/
ematch_container_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
package tc
import (
"errors"
"io"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestContainerMatch(t *testing.T) {
tests := map[string]uint32{
"TestPos5": uint32(5),
"TestPos100": uint32(100),
}
for name, pos := range tests {
t.Run(name, func(t *testing.T) {
in := ContainerMatch{
Pos: pos,
}
data, err := marshalContainerMatch(&in)
if err != nil {
t.Fatal(err)
}
out := ContainerMatch{}
if err := unmarshalContainerMatch(data, &out); err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(in, out); diff != "" {
t.Fatalf("ContainerMatch missmatch (-want +got):\n%s", diff)
}
})
}
t.Run("invalid pos", func(t *testing.T) {
in := ContainerMatch{
Pos: 0,
}
if _, err := marshalContainerMatch(&in); !errors.Is(err, ErrInvalidArg) {
t.Fatalf("Expected ErrInvalidArg but got '%v'", err)
}
})
t.Run("nil-marshalContainerMatch", func(t *testing.T) {
_, err := marshalContainerMatch(nil)
if !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("nil-unmarshalContainerMatch", func(t *testing.T) {
inByte := []byte{0x0001}
if err := unmarshalContainerMatch(inByte, nil); !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("nil-byte-unmarshalContainerMatch", func(t *testing.T) {
out := ContainerMatch{
Pos: 10,
}
if err := unmarshalContainerMatch([]byte{}, &out); !errors.Is(err, io.EOF) {
t.Fatalf("unexpected error: %v", err)
}
})
}