<reponame>Risca/znail
import unittest
from textwrap import dedent
from unittest.mock import patch

from znail.netem.util import restore_hosts_file_to_default


class TestRestoreHostsFileToDefault(unittest.TestCase):
    def test_command_is_rendered_correctly(self):
        with patch("znail.netem.util.run_in_shell") as mock:
            restore_hosts_file_to_default()
            mock.assert_called_once_with(
                dedent(
                    """\
    cat <<EOF> /etc/hosts
    127.0.0.1 localhost
    127.0.1.1 $(hostname)

    # The following lines are desirable for IPv6 capable hosts
    ::1     ip6-localhost ip6-loopback
    fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b ip6-localnet
    fc00:db20:35b:7399::5 ip6-mcastprefix
    fc00:db20:35b:7399::5 ip6-allnodes
    fc00:db20:35b:7399::5 ip6-allrouters
    fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b ip6-allhosts
    EOF
    """
                )
            )

import unittest
from textwrap import dedent
from unittest.mock import patch

from znail.netem.util import restore_hosts_file_to_default


class TestRestoreHostsFileToDefault(unittest.TestCase):
    def test_command_is_rendered_correctly(self):
        with patch("znail.netem.util.run_in_shell") as mock:
            restore_hosts_file_to_default()
            mock.assert_called_once_with(
                dedent(
                    """\
    cat <<EOF> /etc/hosts
    127.0.0.1 localhost
    127.0.1.1 $(hostname)

    # The following lines are desirable for IPv6 capable hosts
    ::1     ip6-localhost ip6-loopback
    fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b ip6-localnet
    fc00:db20:35b:7399::5 ip6-mcastprefix
    fc00:db20:35b:7399::5 ip6-allnodes
    fc00:db20:35b:7399::5 ip6-allrouters
    fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b ip6-allhosts
    EOF
    """
                )
            )
\     cat <<EOF> /etc/hosts     127.0.0.1 localhost     127.0.1.1 $(hostname)      # The following lines are desirable for IPv6 capable hosts     ::1     ip6-localhost ip6-loopback     fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b ip6-localnet     fc00:db20:35b:7399::5 ip6-mcastprefix     fc00:db20:35b:7399::5 ip6-allnodes     fc00:db20:35b:7399::5 ip6-allrouters     fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b ip6-allhosts     EOF