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

Function TestConfigMaps_updatePeers_new

tailnet/configmaps_internal_test.go:118–186  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

116}
117
118func TestConfigMaps_updatePeers_new(t *testing.T) {
119 t.Parallel()
120 ctx := testutil.Context(t, testutil.WaitShort)
121 logger := testutil.Logger(t)
122 fEng := newFakeEngineConfigurable()
123 nodePrivateKey := key.NewNode()
124 nodeID := tailcfg.NodeID(5)
125 discoKey := key.NewDisco()
126 uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), CoderDNSSuffixFQDN)
127 defer uut.close()
128
129 p1ID := uuid.UUID{1}
130 p1Node := newTestNode(1)
131 p1n, err := NodeToProto(p1Node)
132 require.NoError(t, err)
133 p2ID := uuid.UUID{2}
134 p2Node := newTestNode(2)
135 p2n, err := NodeToProto(p2Node)
136 require.NoError(t, err)
137
138 go func() {
139 b := <-fEng.status
140 b.AddPeer(p1Node.Key, &ipnstate.PeerStatus{
141 PublicKey: p1Node.Key,
142 LastHandshake: time.Date(2024, 1, 7, 12, 13, 10, 0, time.UTC),
143 Active: true,
144 })
145 // peer 2 is missing, so it won't have KeepAlives set
146 fEng.statusDone <- struct{}{}
147 }()
148
149 updates := []*proto.CoordinateResponse_PeerUpdate{
150 {
151 Id: p1ID[:],
152 Kind: proto.CoordinateResponse_PeerUpdate_NODE,
153 Node: p1n,
154 },
155 {
156 Id: p2ID[:],
157 Kind: proto.CoordinateResponse_PeerUpdate_NODE,
158 Node: p2n,
159 },
160 }
161 uut.updatePeers(updates)
162
163 nm := testutil.TryReceive(ctx, t, fEng.setNetworkMap)
164 r := testutil.TryReceive(ctx, t, fEng.reconfig)
165
166 require.Len(t, nm.Peers, 2)
167 n1 := getNodeWithID(t, nm.Peers, 1)
168 require.Equal(t, "127.3.3.40:1", n1.DERP)
169 require.Equal(t, p1Node.Endpoints, n1.Endpoints)
170 require.True(t, n1.KeepAlive)
171 n2 := getNodeWithID(t, nm.Peers, 2)
172 require.Equal(t, "127.3.3.40:2", n2.DERP)
173 require.Equal(t, p2Node.Endpoints, n2.Endpoints)
174 require.False(t, n2.KeepAlive)
175

Callers

nothing calls this directly

Calls 12

ContextFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
newConfigMapsFunction · 0.85
newTestNodeFunction · 0.85
NodeToProtoFunction · 0.85
getNodeWithIDFunction · 0.85
updatePeersMethod · 0.80
closeMethod · 0.65
LenMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected