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

Function TestCoordinatorPropogatedPeerContext

tailnet/coordinator_test.go:277–306  ·  view source on GitHub ↗

TestCoordinatorPropogatedPeerContext tests that the context for a specific peer is propogated through to the `Authorize“ method of the coordinatee auth

(t *testing.T)

Source from the content-addressed store, hash-verified

275// TestCoordinatorPropogatedPeerContext tests that the context for a specific peer
276// is propogated through to the `Authorize“ method of the coordinatee auth
277func TestCoordinatorPropogatedPeerContext(t *testing.T) {
278 t.Parallel()
279
280 ctx := testutil.Context(t, testutil.WaitShort)
281 logger := testutil.Logger(t)
282
283 peerCtx := context.WithValue(ctx, test.FakeSubjectKey{}, struct{}{})
284 peerCtx, peerCtxCancel := context.WithCancel(peerCtx)
285 peerID := uuid.UUID{0x01}
286 agentID := uuid.UUID{0x02}
287
288 c1 := tailnet.NewCoordinator(logger)
289 t.Cleanup(func() {
290 err := c1.Close()
291 require.NoError(t, err)
292 })
293
294 ch := make(chan struct{})
295 auth := test.FakeCoordinateeAuth{
296 Chan: ch,
297 }
298
299 reqs, _ := c1.Coordinate(peerCtx, peerID, "peer1", auth)
300
301 testutil.RequireSend(ctx, t, reqs, &proto.CoordinateRequest{AddTunnel: &proto.CoordinateRequest_Tunnel{Id: tailnet.UUIDToByteSlice(agentID)}})
302 _ = testutil.TryReceive(ctx, t, ch)
303 // If we don't cancel the context, the coordinator close will wait until the
304 // peer request loop finishes, which will be after the timeout
305 peerCtxCancel()
306}

Callers

nothing calls this directly

Calls 9

ContextFunction · 0.92
LoggerFunction · 0.92
NewCoordinatorFunction · 0.92
RequireSendFunction · 0.92
UUIDToByteSliceFunction · 0.92
TryReceiveFunction · 0.92
CleanupMethod · 0.65
CloseMethod · 0.65
CoordinateMethod · 0.65

Tested by

no test coverage detected