-
Notifications
You must be signed in to change notification settings - Fork 42
/
json_test.go
59 lines (47 loc) · 1.36 KB
/
json_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
package ipam
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestPrefixes_JSON(t *testing.T) {
p1 := Prefix{
Cidr: "192.168.0.0/24",
ParentCidr: "192.168.0.0/20",
isParent: false,
availableChildPrefixes: map[string]bool{},
childPrefixLength: 0,
ips: map[string]bool{"192.168.0.1": true, "192.168.0.2": true},
version: 0,
}
p2 := Prefix{
Cidr: "172.17.0.0/24",
ParentCidr: "172.17.0.0/20",
isParent: false,
availableChildPrefixes: map[string]bool{},
childPrefixLength: 0,
ips: map[string]bool{"172.17.0.1": true, "172.17.0.2": true},
version: 0,
}
p1j, err := p1.toJSON()
require.NoError(t, err)
require.NotNil(t, p1j)
p2j, err := p2.toJSON()
require.NoError(t, err)
require.NotNil(t, p1j)
p1reverse, err := fromJSON(p1j)
require.NoError(t, err)
require.NotNil(t, p1reverse)
require.Equal(t, p1, p1reverse)
p2reverse, err := fromJSON(p2j)
require.NoError(t, err)
require.NotNil(t, p2reverse)
require.Equal(t, p2, p2reverse)
ps1 := Prefixes{p1, p2}
ps1j, err := ps1.toJSON()
require.NoError(t, err)
require.NotNil(t, ps1j)
ps1reverse, err := fromJSONs(ps1j)
require.NoError(t, err)
require.NotNil(t, ps1reverse)
require.Equal(t, ps1, ps1reverse)
}