MCPcopy Create free account
hub / github.com/PasarGuard/node / createNamespaceFixture

Function createNamespaceFixture

backend/wireguard/integration_e2e_test.go:110–145  ·  view source on GitHub ↗
(t *testing.T, id int)

Source from the content-addressed store, hash-verified

108}
109
110func createNamespaceFixture(t *testing.T, id int) *namespaceFixture {
111 t.Helper()
112
113 ns := fmt.Sprintf("wg-e2e-%d", id)
114 hostVeth := fmt.Sprintf("vethh%d", id)
115 nsVeth := fmt.Sprintf("vethn%d", id)
116 hostTransitIP := fmt.Sprintf("172.30.%d.1", id)
117 nsTransitIP := fmt.Sprintf("172.30.%d.2", id)
118 transitCIDRHost := hostTransitIP + "/30"
119 transitCIDRNS := nsTransitIP + "/30"
120
121 // Best-effort cleanup in case a previous run left stale resources.
122 runCommandNoFail("ip", "netns", "del", ns)
123 runCommandNoFail("ip", "link", "del", hostVeth)
124
125 runCommand(t, "ip", "netns", "add", ns)
126 runCommand(t, "ip", "link", "add", hostVeth, "type", "veth", "peer", "name", nsVeth)
127 runCommand(t, "ip", "link", "set", nsVeth, "netns", ns)
128 runCommand(t, "ip", "addr", "add", transitCIDRHost, "dev", hostVeth)
129 runCommand(t, "ip", "link", "set", hostVeth, "up")
130 runCommand(t, "ip", "netns", "exec", ns, "ip", "link", "set", "lo", "up")
131 runCommand(t, "ip", "netns", "exec", ns, "ip", "addr", "add", transitCIDRNS, "dev", nsVeth)
132 runCommand(t, "ip", "netns", "exec", ns, "ip", "link", "set", nsVeth, "up")
133
134 t.Cleanup(func() {
135 runCommandNoFail("ip", "link", "del", hostVeth)
136 runCommandNoFail("ip", "netns", "del", ns)
137 })
138
139 return &namespaceFixture{
140 name: ns,
141 hostVeth: hostVeth,
142 nsVeth: nsVeth,
143 hostTransitIP: hostTransitIP,
144 }
145}
146
147func wireGuardServerIPByFamily(t *testing.T, wg *WireGuard, wantIPv6 bool) string {
148 t.Helper()

Calls 2

runCommandNoFailFunction · 0.85
runCommandFunction · 0.85

Tested by

no test coverage detected