-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzlib_test.go
54 lines (48 loc) · 1.04 KB
/
zlib_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
/*
* Copyright (c) 2017 by Farsight Security, Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package nmsg_test
import (
"bytes"
"testing"
"github.com/farsightsec/go-nmsg"
)
func TestZlib(t *testing.T) {
b := new(bytes.Buffer)
m := testMessage(20)
p, err := nmsg.Payload(m)
if err != nil {
t.Fatal(err)
}
out := nmsg.UnbufferedOutput(b)
out.SetCompression(true)
out.SetMaxSize(1500, 0)
if err := out.Send(p); err != nil {
t.Fatal(err)
}
inp := nmsg.NewInput(b, 1500)
p, err = inp.Recv()
if err != nil {
t.Fatal(err)
}
mm, err := p.Message()
if err != nil {
t.Fatal(err)
}
mi, ok := mm.(*TestMessage)
if !ok {
t.Error("received message of wrong type")
}
if len(mi.Bytes) != len(m.(*TestMessage).Bytes) {
t.Error("received message of wrong length")
}
for i := range mi.Bytes {
if mi.Bytes[i] != 0 {
t.Fatal("received message with wrong data")
}
}
}