(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestConvertDNSConfig(t *testing.T) { |
| 13 | t.Parallel() |
| 14 | |
| 15 | tests := []struct { |
| 16 | name string |
| 17 | input dns.OSConfig |
| 18 | expected *NetworkSettingsRequest_DNSSettings |
| 19 | }{ |
| 20 | { |
| 21 | name: "Basic", |
| 22 | input: dns.OSConfig{ |
| 23 | Nameservers: []netip.Addr{ |
| 24 | netip.MustParseAddr("1.1.1.1"), |
| 25 | netip.MustParseAddr("8.8.8.8"), |
| 26 | }, |
| 27 | SearchDomains: []dnsname.FQDN{ |
| 28 | "example.com.", |
| 29 | "test.local.", |
| 30 | }, |
| 31 | MatchDomains: []dnsname.FQDN{ |
| 32 | "internal.domain.", |
| 33 | }, |
| 34 | }, |
| 35 | expected: &NetworkSettingsRequest_DNSSettings{ |
| 36 | Servers: []string{"1.1.1.1", "8.8.8.8"}, |
| 37 | SearchDomains: []string{"example.com", "test.local"}, |
| 38 | DomainName: "coder", |
| 39 | MatchDomains: []string{"internal.domain"}, |
| 40 | MatchDomainsNoSearch: false, |
| 41 | }, |
| 42 | }, |
| 43 | { |
| 44 | name: "Empty", |
| 45 | input: dns.OSConfig{ |
| 46 | Nameservers: []netip.Addr{}, |
| 47 | SearchDomains: []dnsname.FQDN{}, |
| 48 | MatchDomains: []dnsname.FQDN{}, |
| 49 | }, |
| 50 | expected: &NetworkSettingsRequest_DNSSettings{ |
| 51 | Servers: []string{}, |
| 52 | SearchDomains: []string{}, |
| 53 | DomainName: "coder", |
| 54 | MatchDomains: []string{}, |
| 55 | MatchDomainsNoSearch: false, |
| 56 | }, |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | for _, tt := range tests { |
| 61 | t.Run(tt.name, func(t *testing.T) { |
| 62 | t.Parallel() |
| 63 | |
| 64 | result := convertDNSConfig(tt.input) |
| 65 | require.Equal(t, tt.expected.Servers, result.Servers) |
| 66 | require.Equal(t, tt.expected.SearchDomains, result.SearchDomains) |
| 67 | require.Equal(t, tt.expected.DomainName, result.DomainName) |
| 68 | require.Equal(t, tt.expected.MatchDomains, result.MatchDomains) |
| 69 | require.Equal(t, tt.expected.MatchDomainsNoSearch, result.MatchDomainsNoSearch) |
nothing calls this directly
no test coverage detected