@@ -571,6 +571,88 @@ func TestConfigMaps_setBlockEndpoints_same(t *testing.T) {
571
571
_ = testutil .RequireRecvCtx (ctx , t , done )
572
572
}
573
573
574
+ func TestConfigMaps_setDERPMap_different (t * testing.T ) {
575
+ t .Parallel ()
576
+ ctx := testutil .Context (t , testutil .WaitShort )
577
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
578
+ fEng := newFakeEngineConfigurable ()
579
+ nodePrivateKey := key .NewNode ()
580
+ nodeID := tailcfg .NodeID (5 )
581
+ discoKey := key .NewDisco ()
582
+ uut := newConfigMaps (logger , fEng , nodeID , nodePrivateKey , discoKey .Public (), nil )
583
+ defer uut .close ()
584
+
585
+ derpMap := & proto.DERPMap {
586
+ HomeParams : & proto.DERPMap_HomeParams {RegionScore : map [int64 ]float64 {1 : 0.025 }},
587
+ Regions : map [int64 ]* proto.DERPMap_Region {
588
+ 1 : {
589
+ RegionCode : "AUH" ,
590
+ Nodes : []* proto.DERPMap_Region_Node {
591
+ {Name : "AUH0" },
592
+ },
593
+ },
594
+ },
595
+ }
596
+ uut .setDERPMap (derpMap )
597
+
598
+ dm := testutil .RequireRecvCtx (ctx , t , fEng .setDERPMap )
599
+ require .Len (t , dm .HomeParams .RegionScore , 1 )
600
+ require .Equal (t , dm .HomeParams .RegionScore [1 ], 0.025 )
601
+ require .Len (t , dm .Regions , 1 )
602
+ r1 := dm .Regions [1 ]
603
+ require .Equal (t , "AUH" , r1 .RegionCode )
604
+ require .Len (t , r1 .Nodes , 1 )
605
+ require .Equal (t , "AUH0" , r1 .Nodes [0 ].Name )
606
+
607
+ done := make (chan struct {})
608
+ go func () {
609
+ defer close (done )
610
+ uut .close ()
611
+ }()
612
+ _ = testutil .RequireRecvCtx (ctx , t , done )
613
+ }
614
+
615
+ func TestConfigMaps_setDERPMap_same (t * testing.T ) {
616
+ t .Parallel ()
617
+ ctx := testutil .Context (t , testutil .WaitShort )
618
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
619
+ fEng := newFakeEngineConfigurable ()
620
+ nodePrivateKey := key .NewNode ()
621
+ nodeID := tailcfg .NodeID (5 )
622
+ discoKey := key .NewDisco ()
623
+ uut := newConfigMaps (logger , fEng , nodeID , nodePrivateKey , discoKey .Public (), nil )
624
+ defer uut .close ()
625
+
626
+ // Given: DERP Map already set
627
+ derpMap := & proto.DERPMap {
628
+ HomeParams : & proto.DERPMap_HomeParams {RegionScore : map [int64 ]float64 {1 : 0.025 }},
629
+ Regions : map [int64 ]* proto.DERPMap_Region {
630
+ 1 : {
631
+ RegionCode : "AUH" ,
632
+ Nodes : []* proto.DERPMap_Region_Node {
633
+ {Name : "AUH0" },
634
+ },
635
+ },
636
+ },
637
+ }
638
+ uut .L .Lock ()
639
+ uut .derpMap = derpMap
640
+ uut .L .Unlock ()
641
+
642
+ // Then: we don't configure
643
+ requireNeverConfigures (ctx , t , & uut .phased )
644
+
645
+ // When we set the same DERP map
646
+ uut .setDERPMap (derpMap )
647
+
648
+ done := make (chan struct {})
649
+ go func () {
650
+ defer close (done )
651
+ uut .close ()
652
+ }()
653
+ _ = testutil .RequireRecvCtx (ctx , t , done )
654
+ }
655
+
574
656
func expectStatusWithHandshake (
575
657
ctx context.Context , t testing.TB , fEng * fakeEngineConfigurable , k key.NodePublic , lastHandshake time.Time ,
576
658
) <- chan struct {} {
@@ -696,6 +778,7 @@ type fakeEngineConfigurable struct {
696
778
setNetworkMap chan * netmap.NetworkMap
697
779
reconfig chan reconfigCall
698
780
filter chan * filter.Filter
781
+ setDERPMap chan * tailcfg.DERPMap
699
782
700
783
// To fake these fields the test should read from status, do stuff to the
701
784
// StatusBuilder, then write to statusDone
@@ -713,6 +796,7 @@ func newFakeEngineConfigurable() *fakeEngineConfigurable {
713
796
setNetworkMap : make (chan * netmap.NetworkMap ),
714
797
reconfig : make (chan reconfigCall ),
715
798
filter : make (chan * filter.Filter ),
799
+ setDERPMap : make (chan * tailcfg.DERPMap ),
716
800
status : make (chan * ipnstate.StatusBuilder ),
717
801
statusDone : make (chan struct {}),
718
802
}
@@ -727,9 +811,8 @@ func (f fakeEngineConfigurable) Reconfig(wg *wgcfg.Config, r *router.Config, _ *
727
811
return nil
728
812
}
729
813
730
- func (fakeEngineConfigurable ) SetDERPMap (* tailcfg.DERPMap ) {
731
- // TODO implement me
732
- panic ("implement me" )
814
+ func (f fakeEngineConfigurable ) SetDERPMap (d * tailcfg.DERPMap ) {
815
+ f .setDERPMap <- d
733
816
}
734
817
735
818
func (f fakeEngineConfigurable ) SetFilter (flt * filter.Filter ) {
0 commit comments