MCPcopy Create free account
hub / github.com/coder/coder / Test_storeBinding

Function Test_storeBinding

enterprise/tailnet/pgcoord_internal_test.go:561–627  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

559}
560
561func Test_storeBinding(t *testing.T) {
562 t.Parallel()
563
564 t.Run("SkipsNoop", func(t *testing.T) {
565 t.Parallel()
566
567 key := bKey(uuid.New())
568 node := &proto.Node{PreferredDerp: 1}
569
570 b := &binder{
571 latest: make(map[bKey]binding),
572 }
573
574 bnd := binding{bKey: key, node: node, kind: proto.CoordinateResponse_PeerUpdate_NODE}
575
576 // First store should succeed.
577 assert.True(t, b.storeBinding(bnd))
578
579 // Same node (even with different AsOf) should be skipped.
580 bnd2 := binding{
581 bKey: key,
582 node: &proto.Node{PreferredDerp: 1, AsOf: timestamppb.Now()},
583 kind: proto.CoordinateResponse_PeerUpdate_NODE,
584 }
585 assert.False(t, b.storeBinding(bnd2))
586 })
587
588 t.Run("AllowsChangedNode", func(t *testing.T) {
589 t.Parallel()
590
591 key := bKey(uuid.New())
592
593 b := &binder{
594 latest: make(map[bKey]binding),
595 }
596
597 bnd1 := binding{bKey: key, node: &proto.Node{PreferredDerp: 1}, kind: proto.CoordinateResponse_PeerUpdate_NODE}
598 assert.True(t, b.storeBinding(bnd1))
599
600 bnd2 := binding{bKey: key, node: &proto.Node{PreferredDerp: 2}, kind: proto.CoordinateResponse_PeerUpdate_NODE}
601 assert.True(t, b.storeBinding(bnd2))
602 })
603
604 t.Run("LostToNodeTransition", func(t *testing.T) {
605 t.Parallel()
606
607 key := bKey(uuid.New())
608
609 b := &binder{
610 latest: make(map[bKey]binding),
611 }
612
613 node := &proto.Node{PreferredDerp: 1}
614
615 // NODE should enqueue.
616 bnd1 := binding{bKey: key, node: node, kind: proto.CoordinateResponse_PeerUpdate_NODE}
617 assert.True(t, b.storeBinding(bnd1))
618

Callers

nothing calls this directly

Calls 4

storeBindingMethod · 0.95
bKeyTypeAlias · 0.85
RunMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected