-
Notifications
You must be signed in to change notification settings - Fork 1
/
writer_test.go
81 lines (73 loc) · 1.58 KB
/
writer_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
package gosc
import (
"bufio"
"bytes"
"testing"
)
type fakePackage struct{}
func (f *fakePackage) GetType() PackageType {
return "fake"
}
func Test_writePackage(t *testing.T) {
buf := bytes.Buffer{}
w := bufio.NewWriter(&buf)
t.Run("message", func(t *testing.T) {
err := writePackage(&Message{
Address: "/info",
Arguments: []any{float32(1.0), "Test", int32(2)},
}, w)
if err != nil {
t.Errorf("expected no error but got: %v", err)
}
})
t.Run("bundle", func(t *testing.T) {
err := writePackage(&Bundle{
Timetag: 0,
Messages: []*Message{
{
Address: "/info",
Arguments: []any{},
},
},
Bundles: []*Bundle{},
Name: "TestName",
}, w)
if err != nil {
t.Errorf("expected no error but got: %v", err)
}
})
t.Run("unknown", func(t *testing.T) {
err := writePackage(&fakePackage{}, w)
if err == nil {
t.Error("expected error but none given")
}
})
}
func Test_writeArguments(t *testing.T) {
buf := bytes.Buffer{}
w := bufio.NewWriter(&buf)
err := writeArguments(w, []any{})
if err != nil {
t.Errorf("expected no error but got: %v", err)
}
_ = w.Flush()
if buf.Len() != 4 {
t.Errorf("arguments was %d bytes but expected 4", buf.Len())
}
}
func Test_writePaddedString(t *testing.T) {
buf := bytes.Buffer{}
w := bufio.NewWriter(&buf)
data := "/info"
err := writePaddedString(w, data)
if err != nil {
t.Errorf("expected no error but got: %v", err)
}
_ = w.Flush()
if buf.Len() != 8 {
t.Errorf("padded string was %d bytes but expected 8", buf.Len())
}
}
func Test_writePayload(t *testing.T) {
// TODO: Implement me
}