@@ -571,6 +571,88 @@ func TestConfigMaps_setBlockEndpoints_same(t *testing.T) {
571571 _ = testutil .RequireRecvCtx (ctx , t , done )
572572}
573573
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+
574656func expectStatusWithHandshake (
575657 ctx context.Context , t testing.TB , fEng * fakeEngineConfigurable , k key.NodePublic , lastHandshake time.Time ,
576658) <- chan struct {} {
@@ -696,6 +778,7 @@ type fakeEngineConfigurable struct {
696778 setNetworkMap chan * netmap.NetworkMap
697779 reconfig chan reconfigCall
698780 filter chan * filter.Filter
781+ setDERPMap chan * tailcfg.DERPMap
699782
700783 // To fake these fields the test should read from status, do stuff to the
701784 // StatusBuilder, then write to statusDone
@@ -713,6 +796,7 @@ func newFakeEngineConfigurable() *fakeEngineConfigurable {
713796 setNetworkMap : make (chan * netmap.NetworkMap ),
714797 reconfig : make (chan reconfigCall ),
715798 filter : make (chan * filter.Filter ),
799+ setDERPMap : make (chan * tailcfg.DERPMap ),
716800 status : make (chan * ipnstate.StatusBuilder ),
717801 statusDone : make (chan struct {}),
718802 }
@@ -727,9 +811,8 @@ func (f fakeEngineConfigurable) Reconfig(wg *wgcfg.Config, r *router.Config, _ *
727811 return nil
728812}
729813
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
733816}
734817
735818func (f fakeEngineConfigurable ) SetFilter (flt * filter.Filter ) {
0 commit comments