-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
44 lines (37 loc) · 1.17 KB
/
main_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
package main
import (
"testing"
"bytes"
)
func TestEncode(t *testing.T) {
// given
input := []byte("Testing zpipe implementation.")
expected := []byte{
0x78, 0x9c, 0x0a, 0x49, 0x2d, 0x2e, 0xc9, 0xcc, 0x4b, 0x57, 0xa8, 0x2a, 0xc8, 0x2c, 0x48, 0x55,
0xc8, 0xcc, 0x2d, 0xc8, 0x49, 0xcd, 0x4d, 0xcd, 0x2b, 0x49, 0x2c, 0xc9, 0xcc, 0xcf, 0xd3, 0x03,
0x04, 0x00, 0x00, 0xff, 0xff, 0xaa, 0x6e, 0x0b, 0x5b,
}
// when
var actual bytes.Buffer
encode(bytes.NewReader(input), &actual)
//then
if bytes.Compare(expected, actual.Bytes()) != 0 {
t.Errorf("Expected: %v, got: %v", expected, actual.Bytes())
}
}
func TestDecode(t *testing.T) {
// given
input := []byte{
0x78, 0x9c, 0x0a, 0x49, 0x2d, 0x2e, 0xc9, 0xcc, 0x4b, 0x57, 0xa8, 0x2a, 0xc8, 0x2c, 0x48, 0x55,
0xc8, 0xcc, 0x2d, 0xc8, 0x49, 0xcd, 0x4d, 0xcd, 0x2b, 0x49, 0x2c, 0xc9, 0xcc, 0xcf, 0xd3, 0x03,
0x04, 0x00, 0x00, 0xff, 0xff, 0xaa, 0x6e, 0x0b, 0x5b,
}
expected := []byte("Testing zpipe implementation.")
// when
var actual bytes.Buffer
decode(bytes.NewReader(input), &actual)
//then
if bytes.Compare(expected, actual.Bytes()) != 0 {
t.Errorf("Expected: %v, got: %v", []byte(expected), actual.Bytes())
}
}