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

Function TestNodeUpdater_setCallback

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

Source from the content-addressed store, hash-verified

439}
440
441func TestNodeUpdater_setCallback(t *testing.T) {
442 t.Parallel()
443 ctx := testutil.Context(t, testutil.WaitShort)
444 logger := testutil.Logger(t)
445 id := tailcfg.NodeID(1)
446 nodeKey := key.NewNode().Public()
447 discoKey := key.NewDisco().Public()
448 uut := newNodeUpdater(
449 logger,
450 nil,
451 id, nodeKey, discoKey,
452 )
453 defer uut.close()
454
455 // Given: preferred DERP is 1
456 addrs := []netip.Prefix{netip.MustParsePrefix("192.168.0.200/32")}
457 uut.L.Lock()
458 uut.preferredDERP = 1
459 uut.addresses = slices.Clone(addrs)
460 uut.L.Unlock()
461
462 // When: we set callback
463 nodeCh := make(chan *Node)
464 uut.setCallback(func(n *Node) {
465 nodeCh <- n
466 })
467
468 // Then: we get a node update
469 node := testutil.TryReceive(ctx, t, nodeCh)
470 require.Equal(t, nodeKey, node.Key)
471 require.Equal(t, discoKey, node.DiscoKey)
472 require.Equal(t, 1, node.PreferredDERP)
473
474 done := make(chan struct{})
475 go func() {
476 defer close(done)
477 uut.close()
478 }()
479 _ = testutil.TryReceive(ctx, t, done)
480}
481
482func TestNodeUpdater_setBlockEndpoints_different(t *testing.T) {
483 t.Parallel()

Callers

nothing calls this directly

Calls 10

ContextFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
newNodeUpdaterFunction · 0.85
setCallbackMethod · 0.80
closeMethod · 0.65
LockMethod · 0.45
CloneMethod · 0.45
UnlockMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected