(t *testing.T)
| 480 | } |
| 481 | |
| 482 | func 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 | |
| 531 | func TestNodeUpdater_setBlockEndpoints_same(t *testing.T) { |
| 532 | t.Parallel() |
nothing calls this directly
no test coverage detected