(t *testing.T)
| 1157 | } |
| 1158 | |
| 1159 | func TestConfigMaps_addRemoveHosts(t *testing.T) { |
| 1160 | t.Parallel() |
| 1161 | |
| 1162 | ctx := testutil.Context(t, testutil.WaitShort) |
| 1163 | logger := testutil.Logger(t) |
| 1164 | fEng := newFakeEngineConfigurable() |
| 1165 | nodePrivateKey := key.NewNode() |
| 1166 | nodeID := tailcfg.NodeID(5) |
| 1167 | discoKey := key.NewDisco() |
| 1168 | suffix := dnsname.FQDN("test.") |
| 1169 | uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), suffix) |
| 1170 | defer uut.close() |
| 1171 | |
| 1172 | addr1 := CoderServicePrefix.AddrFromUUID(uuid.New()) |
| 1173 | addr2 := CoderServicePrefix.AddrFromUUID(uuid.New()) |
| 1174 | addr3 := CoderServicePrefix.AddrFromUUID(uuid.New()) |
| 1175 | addr4 := CoderServicePrefix.AddrFromUUID(uuid.New()) |
| 1176 | |
| 1177 | // WHEN: we set two hosts |
| 1178 | uut.setHosts(map[dnsname.FQDN][]netip.Addr{ |
| 1179 | "agent.myws.me.coder.": { |
| 1180 | addr1, |
| 1181 | }, |
| 1182 | "dev.main.me.coder.": { |
| 1183 | addr2, |
| 1184 | addr3, |
| 1185 | }, |
| 1186 | }) |
| 1187 | |
| 1188 | // THEN: the engine is reconfigured with those same hosts |
| 1189 | _ = testutil.TryReceive(ctx, t, fEng.setNetworkMap) |
| 1190 | req := testutil.TryReceive(ctx, t, fEng.reconfig) |
| 1191 | require.Equal(t, req.dnsCfg, &dns.Config{ |
| 1192 | Routes: map[dnsname.FQDN][]*dnstype.Resolver{ |
| 1193 | suffix: nil, |
| 1194 | }, |
| 1195 | // Note that host names and Routes are independent --- so we faithfully reproduce the hosts, even though |
| 1196 | // they don't match the route. |
| 1197 | Hosts: map[dnsname.FQDN][]netip.Addr{ |
| 1198 | "agent.myws.me.coder.": { |
| 1199 | addr1, |
| 1200 | }, |
| 1201 | "dev.main.me.coder.": { |
| 1202 | addr2, |
| 1203 | addr3, |
| 1204 | }, |
| 1205 | }, |
| 1206 | OnlyIPv6: true, |
| 1207 | }) |
| 1208 | |
| 1209 | // WHEN: We replace the hosts with a new set |
| 1210 | uut.setHosts(map[dnsname.FQDN][]netip.Addr{ |
| 1211 | "newagent.myws.me.coder.": { |
| 1212 | addr4, |
| 1213 | }, |
| 1214 | "newagent2.main.me.coder.": { |
| 1215 | addr1, |
| 1216 | }, |
nothing calls this directly
no test coverage detected