-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnfrules_marshal_test.go
41 lines (39 loc) · 1.01 KB
/
nfrules_marshal_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
package nftableslib
import (
"strings"
"testing"
)
func TestBuildIPv6String(t *testing.T) {
tests := []struct {
name string
raw []byte
want string
}{
{
name: "ipv6 default address",
raw: []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
want: "::",
},
{
name: "ipv6 loopback address",
raw: []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
want: "::1",
},
{
name: "compressed from begining ipv6 addresss",
raw: []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x12, 0x34, 0x0, 0x1},
want: "::1234:1",
},
{
name: "compressed in the middle ipv6 address",
raw: []byte{0x20, 0x01, 0xa1, 0xb2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x12, 0x34, 0x0, 0x1},
want: "2001:a1b2::1234:1",
},
}
for _, tt := range tests {
got := buildIPv6String(tt.raw)
if strings.Compare(got, tt.want) != 0 {
t.Fatalf("test %s failed, got: %s want: %s", tt.name, got, tt.want)
}
}
}