@@ -218,3 +218,77 @@ func TestRouteHelpDocumentsOverrides(t *testing.T) {
218218 }
219219 }
220220}
221+
222+ func TestDefaultIPRouteListIncludesEveryDetectedRoute (t * testing.T ) {
223+ prefix := netip .MustParsePrefix ("10.0.0.0/8" )
224+ routes := controlapi.IPRoutes {
225+ Bindings : []controlapi.IPRouteBinding {{
226+ Prefix : prefix , ProfileID : "work-id" , ProfileName : "work" , Policy : "bound" ,
227+ PrimaryRouter : "work-router" , State : "installed" ,
228+ }},
229+ Available : []controlapi.AvailableIPRoute {
230+ {Prefix : prefix , ProfileID : "work-id" , ProfileName : "work" , PrimaryRouter : "work-router" },
231+ {Prefix : prefix , ProfileID : "work-id" , ProfileName : "work" , PrimaryRouter : "backup-router" },
232+ {Prefix : prefix , ProfileID : "lab-id" , ProfileName : "lab" , PrimaryRouter : "lab-router" },
233+ {Prefix : netip .MustParsePrefix ("172.16.0.0/12" ), ProfileID : "lab-id" , ProfileName : "lab" , PrimaryRouter : "lab-router" },
234+ },
235+ }
236+ var output bytes.Buffer
237+ writeIPRoutes (& output , routes , false )
238+ if got := strings .Count (output .String (), prefix .String ()); got != 3 {
239+ t .Fatalf ("route appears %d times, want selected plus every other detection:\n %s" , got , output .String ())
240+ }
241+ for _ , want := range []string {"172.16.0.0/12" , "detected" , "available" , "lab-router" , "backup-router" } {
242+ if ! strings .Contains (output .String (), want ) {
243+ t .Fatalf ("IP route list does not contain %q:\n %s" , want , output .String ())
244+ }
245+ }
246+ }
247+
248+ func TestDefaultDNSRouteListIncludesEveryDetectedRoute (t * testing.T ) {
249+ routes := controlapi.DNSRoutes {
250+ Automatic : []controlapi.DNSRouteBinding {{
251+ Domain : "corp.example" , ProfileID : "work-id" , ProfileName : "work" ,
252+ Source : "magicdns" , Policy : "automatic" , State : "installed" ,
253+ }},
254+ Available : []controlapi.AvailableDNSRoute {
255+ {Domain : "corp.example" , ProfileID : "work-id" , ProfileName : "work" , Source : "magicdns" },
256+ {Domain : "corp.example" , ProfileID : "lab-id" , ProfileName : "lab" , Source : "split-dns" },
257+ {Domain : "dev.example" , ProfileID : "lab-id" , ProfileName : "lab" , Source : "split-dns" },
258+ },
259+ }
260+ var output bytes.Buffer
261+ writeDNSRoutes (& output , routes , false )
262+ if got := strings .Count (output .String (), "corp.example" ); got != 2 {
263+ t .Fatalf ("domain appears %d times, want selected and other-profile detection:\n %s" , got , output .String ())
264+ }
265+ for _ , want := range []string {"dev.example" , "detected" , "available" , "split-dns" } {
266+ if ! strings .Contains (output .String (), want ) {
267+ t .Fatalf ("DNS route list does not contain %q:\n %s" , want , output .String ())
268+ }
269+ }
270+ }
271+
272+ func TestSearchListIncludesEveryDetectedSearchDomain (t * testing.T ) {
273+ domains := controlapi.SearchDomains {
274+ Desired : []string {"corp.example" },
275+ Installed : []controlapi.InstalledSearchDomain {{
276+ Domain : "corp.example" , ProfileID : "work-id" , ProfileName : "work" ,
277+ }},
278+ Available : []controlapi.AvailableSearchDomain {
279+ {Domain : "corp.example" , ProfileID : "work-id" , ProfileName : "work" },
280+ {Domain : "corp.example" , ProfileID : "lab-id" , ProfileName : "lab" },
281+ {Domain : "dev.example" , ProfileID : "lab-id" , ProfileName : "lab" },
282+ },
283+ }
284+ var output bytes.Buffer
285+ writeSearchDomains (& output , domains )
286+ if got := strings .Count (output .String (), "corp.example" ); got != 2 {
287+ t .Fatalf ("search domain appears %d times, want selected and other-profile detection:\n %s" , got , output .String ())
288+ }
289+ for _ , want := range []string {"dev.example" , "available" , "lab" } {
290+ if ! strings .Contains (output .String (), want ) {
291+ t .Fatalf ("search domain list does not contain %q:\n %s" , want , output .String ())
292+ }
293+ }
294+ }
0 commit comments