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)
| 175 | // N-peer analog of tailnet's stitch test helper, so the peers can reach each |
| 176 | // other without a coordinator. |
| 177 | func 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 | } |
no test coverage detected