-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathinfo_cgo_test_support_dev.go
More file actions
82 lines (75 loc) · 1.98 KB
/
Copy pathinfo_cgo_test_support_dev.go
File metadata and controls
82 lines (75 loc) · 1.98 KB
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
//go:build boxlite_dev
package boxlite
/*
#include "bridge.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
// Go does not support importing C from a _test.go file. Keep the native test
// fixtures development-only so prebuilt SDK consumers do not compile test
// support into their package.
func cNetworkInfoTraversalTestFixtures() [4]*NetworkInfo {
allowHost := C.CString("api.example.com")
defer C.free(unsafe.Pointer(allowHost))
allowNet := []*C.char{allowHost}
unresolved := C.CNetworkInfo{
outbound: C.COutboundNetworkInfo{
mode: C.BoxliteNetworkModeEnabled,
allow_net: (**C.char)(unsafe.Pointer(&allowNet[0])),
allow_net_count: 1,
},
inbound: C.CInboundNetworkInfo{
mode: C.BoxliteNetworkModeDisabled,
},
}
resolvedPorts := C.CPublishedPortList{}
resolvedEmpty := C.CNetworkInfo{
outbound: C.COutboundNetworkInfo{
mode: C.BoxliteNetworkModeDisabled,
},
inbound: C.CInboundNetworkInfo{
mode: C.BoxliteNetworkModeEnabled,
},
published_ports: &resolvedPorts,
}
tcpHost := C.CString("127.0.0.1")
defer C.free(unsafe.Pointer(tcpHost))
udpHost := C.CString("::1")
defer C.free(unsafe.Pointer(udpHost))
portItems := []C.CPublishedPort{
{
guest_port: 3000,
host_ip: tcpHost,
host_port: 49152,
protocol: C.BoxlitePortProtocolTcp,
},
{
guest_port: 53,
host_ip: udpHost,
host_port: 5353,
protocol: C.BoxlitePortProtocolUdp,
},
}
populatedPorts := C.CPublishedPortList{
items: &portItems[0],
count: C.int(len(portItems)),
}
populated := C.CNetworkInfo{
outbound: C.COutboundNetworkInfo{
mode: C.BoxliteNetworkModeEnabled,
allow_net: (**C.char)(unsafe.Pointer(&allowNet[0])),
allow_net_count: 1,
},
inbound: C.CInboundNetworkInfo{
mode: C.BoxliteNetworkModeEnabled,
},
published_ports: &populatedPorts,
}
return [4]*NetworkInfo{
cNetworkInfoToGo(nil),
cNetworkInfoToGo(&unresolved),
cNetworkInfoToGo(&resolvedEmpty),
cNetworkInfoToGo(&populated),
}
}