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

Function TestNodeUpdater_setBlockEndpoints_different

tailnet/node_internal_test.go:482–529  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

480}
481
482func TestNodeUpdater_setBlockEndpoints_different(t *testing.T) {
483 t.Parallel()
484 ctx := testutil.Context(t, testutil.WaitShort)
485 logger := testutil.Logger(t)
486 id := tailcfg.NodeID(1)
487 nodeKey := key.NewNode().Public()
488 discoKey := key.NewDisco().Public()
489 nodeCh := make(chan *Node)
490 uut := newNodeUpdater(
491 logger,
492 func(n *Node) {
493 nodeCh <- n
494 },
495 id, nodeKey, discoKey,
496 )
497 defer uut.close()
498
499 // Given: preferred DERP is 1, so we'll send an update && some endpoints
500 uut.L.Lock()
501 uut.preferredDERP = 1
502 uut.endpoints = []string{"10.11.12.13:7890"}
503 uut.L.Unlock()
504
505 // When: we setBlockEndpoints
506 uut.setBlockEndpoints(true)
507
508 // Then: we receive an update without endpoints
509 node := testutil.TryReceive(ctx, t, nodeCh)
510 require.Equal(t, nodeKey, node.Key)
511 require.Equal(t, discoKey, node.DiscoKey)
512 require.Len(t, node.Endpoints, 0)
513
514 // When: we unset BlockEndpoints
515 uut.setBlockEndpoints(false)
516
517 // Then: we receive an update with endpoints
518 node = testutil.TryReceive(ctx, t, nodeCh)
519 require.Equal(t, nodeKey, node.Key)
520 require.Equal(t, discoKey, node.DiscoKey)
521 require.Len(t, node.Endpoints, 1)
522
523 done := make(chan struct{})
524 go func() {
525 defer close(done)
526 uut.close()
527 }()
528 _ = testutil.TryReceive(ctx, t, done)
529}
530
531func TestNodeUpdater_setBlockEndpoints_same(t *testing.T) {
532 t.Parallel()

Callers

nothing calls this directly

Calls 10

ContextFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
newNodeUpdaterFunction · 0.85
closeMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
setBlockEndpointsMethod · 0.45
EqualMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected