def testSettingDuplicateName(self): utils.SetEtcHostsEntry(self.tmpname, "198.51.100.4", "myhost", ["myhost"]) self.assertFileContent(self.tmpname, "# This is a test file for /etc/hosts\n" "127.0.0.1\tlocalhost\n" "192.0.2.1 router gw\n" "198.51.100.4\tmyhost\n") self.assertFileMode(self.tmpname, 0o644)
def testSettingOrdering(self): utils.SetEtcHostsEntry(self.tmpname, "127.0.0.1", "localhost.localdomain", ["localhost"]) self.assertFileContent(self.tmpname, "# This is a test file for /etc/hosts\n" "127.0.0.1\tlocalhost.localdomain localhost\n" "192.0.2.1 router gw\n") self.assertFileMode(self.tmpname, 0o644)
def testSettingExistingIp(self): utils.SetEtcHostsEntry(self.tmpname, "192.0.2.1", "myhost.example.com", ["myhost"]) self.assertFileContent(self.tmpname, "# This is a test file for /etc/hosts\n" "127.0.0.1\tlocalhost\n" "192.0.2.1\tmyhost.example.com myhost\n") self.assertFileMode(self.tmpname, 0o644)