MCPcopy Index your code
hub / github.com/coder/coder / stitchTailnet

Function stitchTailnet

codersdk/workspacesdk/agentconn_test.go:177–212  ·  view source on GitHub ↗

stitchTailnet cross-programs every conn's node into every other conn, the N-peer analog of tailnet's stitch test helper, so the peers can reach each other without a coordinator.

(t *testing.T, conns map[uuid.UUID]*tailnet.Conn)

Source from the content-addressed store, hash-verified

175// N-peer analog of tailnet's stitch test helper, so the peers can reach each
176// other without a coordinator.
177func stitchTailnet(t *testing.T, conns map[uuid.UUID]*tailnet.Conn) {
178 t.Helper()
179
180 sendNode := func(srcID uuid.UUID, node *tailnet.Node) {
181 protoNode, err := tailnet.NodeToProto(node)
182 if !assert.NoError(t, err) {
183 return
184 }
185 for dstID, dst := range conns {
186 if dstID == srcID {
187 continue
188 }
189 err = dst.UpdatePeers([]*proto.CoordinateResponse_PeerUpdate{{
190 Id: srcID[:],
191 Node: protoNode,
192 Kind: proto.CoordinateResponse_PeerUpdate_NODE,
193 }})
194 assert.NoError(t, err)
195 }
196 }
197
198 for srcID, src := range conns {
199 src.SetNodeCallback(func(node *tailnet.Node) {
200 sendNode(srcID, node)
201 })
202 if node := src.Node(); node != nil {
203 sendNode(srcID, node)
204 }
205 }
206
207 t.Cleanup(func() {
208 for _, conn := range conns {
209 conn.SetNodeCallback(nil)
210 }
211 })
212}

Calls 6

NodeToProtoFunction · 0.92
HelperMethod · 0.65
UpdatePeersMethod · 0.65
SetNodeCallbackMethod · 0.65
NodeMethod · 0.65
CleanupMethod · 0.65

Tested by

no test coverage detected