(t *testing.T)
| 189 | } |
| 190 | |
| 191 | func TestUpdateDNSConfig(t *testing.T) { |
| 192 | flags := newUpdateCommand(nil).Flags() |
| 193 | |
| 194 | // IPv4, with duplicates |
| 195 | flags.Set("dns-add", "1.1.1.1") |
| 196 | flags.Set("dns-add", "1.1.1.1") |
| 197 | flags.Set("dns-add", "2.2.2.2") |
| 198 | flags.Set("dns-rm", "3.3.3.3") |
| 199 | flags.Set("dns-rm", "2.2.2.2") |
| 200 | // IPv6 |
| 201 | flags.Set("dns-add", "2001:db8:abc8::1") |
| 202 | // Invalid dns record |
| 203 | assert.Check(t, is.ErrorContains(flags.Set("dns-add", "x.y.z.w"), "IP address is not correctly formatted: x.y.z.w")) |
| 204 | |
| 205 | // domains with duplicates |
| 206 | flags.Set("dns-search-add", "example.com") |
| 207 | flags.Set("dns-search-add", "example.com") |
| 208 | flags.Set("dns-search-add", "example.org") |
| 209 | flags.Set("dns-search-rm", "example.org") |
| 210 | // Invalid dns search domain |
| 211 | assert.ErrorContains(t, flags.Set("dns-search-add", "example$com"), "example$com is not a valid domain") |
| 212 | |
| 213 | flags.Set("dns-option-add", "ndots:9") |
| 214 | flags.Set("dns-option-rm", "timeout:3") |
| 215 | |
| 216 | config := &swarm.DNSConfig{ |
| 217 | Nameservers: []netip.Addr{netip.MustParseAddr("3.3.3.3"), netip.MustParseAddr("5.5.5.5")}, |
| 218 | Search: []string{"localdomain"}, |
| 219 | Options: []string{"timeout:3"}, |
| 220 | } |
| 221 | |
| 222 | updateDNSConfig(flags, &config) |
| 223 | |
| 224 | assert.Assert(t, is.Len(config.Nameservers, 3)) |
| 225 | assert.Check(t, is.Equal(netip.MustParseAddr("1.1.1.1"), config.Nameservers[0])) |
| 226 | assert.Check(t, is.Equal(netip.MustParseAddr("5.5.5.5"), config.Nameservers[1])) |
| 227 | assert.Check(t, is.Equal(netip.MustParseAddr("2001:db8:abc8::1"), config.Nameservers[2])) |
| 228 | |
| 229 | assert.Assert(t, is.Len(config.Search, 2)) |
| 230 | assert.Check(t, is.Equal("example.com", config.Search[0])) |
| 231 | assert.Check(t, is.Equal("localdomain", config.Search[1])) |
| 232 | |
| 233 | assert.Assert(t, is.Len(config.Options, 1)) |
| 234 | assert.Check(t, is.Equal(config.Options[0], "ndots:9")) |
| 235 | } |
| 236 | |
| 237 | func TestUpdateMounts(t *testing.T) { |
| 238 | flags := newUpdateCommand(nil).Flags() |
nothing calls this directly
no test coverage detected
searching dependent graphs…