forked from BellerophonMobile/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Connection_test.go
173 lines (164 loc) · 4.64 KB
/
Connection_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package gonetworkmanager
import (
"github.com/godbus/dbus/v5"
"reflect"
"testing"
)
func TestDecodeSettings(t *testing.T) {
settings := map[string]map[string]dbus.Variant{
"ipv4": {
"address-data": dbus.MakeVariant([]map[string]dbus.Variant{
{
"address": dbus.MakeVariant("192.168.1.156"),
"prefix": dbus.MakeVariant(24),
},
}),
"dns-search": dbus.MakeVariant([]string{}),
"method": dbus.MakeVariant("manual"),
"route-data": dbus.MakeVariant([]map[string]dbus.Variant{}),
"routes": dbus.MakeVariant([][]uint32{}),
"addresses": dbus.MakeVariant([][]uint32{
{
2617354432,
24,
16885952,
},
}),
"gateway": dbus.MakeVariant("192.168.1.1"),
"route-metric": dbus.MakeVariant(100),
"dhcp-timeout": dbus.MakeVariant(45),
},
"ipv6": {
"addr-gen-mode": dbus.MakeVariant(3),
"address-data": dbus.MakeVariant([]map[string]dbus.Variant{}),
"routes": dbus.MakeVariant([][]interface{}{}),
"dns-search": dbus.MakeVariant([]string{}),
"method": dbus.MakeVariant("auto"),
"route-data": dbus.MakeVariant([]map[string]dbus.Variant{}),
"dhcp-timeout": dbus.MakeVariant(45),
"route-metric": dbus.MakeVariant(100),
"addresses": dbus.MakeVariant([][]interface{}{}),
},
"proxy": {},
"connection": {
"uuid": dbus.MakeVariant("390e5c2b-7312-415e-80e6-7b94a5c24fc3"),
"autoconnect-priority": dbus.MakeVariant(1),
"autoconnect-retries": dbus.MakeVariant(0),
"id": dbus.MakeVariant("main"),
"interface-name": dbus.MakeVariant("eth0"),
"permissions": dbus.MakeVariant([]string{}),
"timestamp": dbus.MakeVariant(1669049774),
"type": dbus.MakeVariant("802-3-ethernet"),
},
"802-3-ethernet": {
"auto-negotiate": dbus.MakeVariant(false),
"mac-address-blacklist": dbus.MakeVariant([]string{}),
"s390-options": dbus.MakeVariant(map[string]string{}),
},
}
result := decodeSettings(settings)
expected := ConnectionSettings{
"ipv4": {
"address-data": []map[string]interface{}{
{
"address": "192.168.1.156",
"prefix": 24,
},
},
"dns-search": []string{},
"method": "manual",
"route-data": []map[string]interface{}(nil),
"routes": [][]uint32{},
"addresses": [][]uint32{
{
2617354432,
24,
16885952,
},
},
"gateway": "192.168.1.1",
"route-metric": 100,
"dhcp-timeout": 45,
},
"ipv6": {
"addr-gen-mode": 3,
"address-data": []map[string]interface{}(nil),
"routes": [][]interface{}{},
"dns-search": []string{},
"method": "auto",
"route-data": []map[string]interface{}(nil),
"dhcp-timeout": 45,
"route-metric": 100,
"addresses": [][]interface{}{},
},
"proxy": {},
"connection": {
"uuid": "390e5c2b-7312-415e-80e6-7b94a5c24fc3",
"autoconnect-priority": 1,
"autoconnect-retries": 0,
"id": "main",
"interface-name": "eth0",
"permissions": []string{},
"timestamp": 1669049774,
"type": "802-3-ethernet",
},
"802-3-ethernet": {
"auto-negotiate": false,
"mac-address-blacklist": []string{},
"s390-options": map[string]string{},
},
}
if !reflect.DeepEqual(result, expected) {
t.Fatalf("failed: \nexpected: %#v\nresult : %#v", expected, result)
}
}
func TestDecode(t *testing.T) {
ipSettings := map[string]dbus.Variant{
"address-data": dbus.MakeVariant([]map[string]dbus.Variant{
{
"address": dbus.MakeVariant("192.168.1.156"),
"prefix": dbus.MakeVariant(24),
},
}),
"dns-search": dbus.MakeVariant([]string{}),
"method": dbus.MakeVariant("manual"),
"route-data": dbus.MakeVariant([]map[string]dbus.Variant{}),
"routes": dbus.MakeVariant([][]uint32{}),
"addresses": dbus.MakeVariant([][]uint32{
{
2617354432,
24,
16885952,
},
}),
"gateway": dbus.MakeVariant("192.168.1.1"),
"route-metric": dbus.MakeVariant(100),
"dhcp-timeout": dbus.MakeVariant(45),
}
result := decode(ipSettings)
expected := map[string]interface{}{
"address-data": []map[string]interface{}{
{
"address": "192.168.1.156",
"prefix": 24,
},
},
"dns-search": []string{},
"method": "manual",
"route-data": []map[string]interface{}(nil),
"routes": [][]uint32{},
"addresses": [][]uint32{
{
2617354432,
24,
16885952,
},
},
"gateway": "192.168.1.1",
"route-metric": 100,
"dhcp-timeout": 45,
}
if !reflect.DeepEqual(result, expected) {
t.Fatalf("failed: \nexpected: %#v\nresult : %#v", expected, result)
}
}