| 123456789101112131415161718192021222324252627282930 |
- package network
- import (
- "strings"
- "testing"
- )
- func TestPersistencePreservesHostConfiguration(t *testing.T) {
- original := "auto lo\niface lo inet loopback\nauto eth0\niface eth0 inet dhcp\n mtu 1450\n post-up ip route add 10.0.0.0/8 via 192.0.2.1\n"
- ips := map[string][]string{"eth0": {"192.0.2.5/24", "2001:db8::5/64"}}
- updated := withSourceInclude(withManagedAddresses(original, ips))
- for _, line := range strings.Split(strings.TrimSpace(original), "\n") {
- if !strings.Contains(updated, line) {
- t.Fatalf("lost host setting: %s", line)
- }
- }
- if strings.Count(updated, "iface eth0") != 1 || strings.Count(updated, "source /etc/network/interfaces.d/*") != 1 {
- t.Fatal(updated)
- }
- if !strings.Contains(updated, "2001:db8::5/64") {
- t.Fatal("IPv6 address lost")
- }
- if again := withSourceInclude(withManagedAddresses(updated, ips)); again != updated {
- t.Fatal("repeated persistence changed configuration")
- }
- removed := withManagedAddresses(updated, map[string][]string{})
- if strings.Contains(removed, "192.0.2.5") || !strings.Contains(removed, "inet dhcp") {
- t.Fatal("address deletion touched host config or retained removed address")
- }
- }
|