diff --git a/bin/test_executenode.py b/bin/test_executenode.py index e260182..6ece414 100644 --- a/bin/test_executenode.py +++ b/bin/test_executenode.py @@ -4,6 +4,7 @@ import unittest from zfs_autobackup import * import subprocess +import time print("THIS TEST REQUIRES SSH TO LOCALHOST") @@ -15,8 +16,8 @@ class TestExecuteNode(unittest.TestCase): def basics(self, node ): - #single line with spaces - self.assertEqual(node.run(["echo","test test"]), ["test test"]) + #single line + self.assertEqual(node.run(["echo","test"]), ["test"]) #error exit code with self.assertRaises(subprocess.CalledProcessError): @@ -24,18 +25,26 @@ class TestExecuteNode(unittest.TestCase): #multiline without tabsplit self.assertEqual(node.run(["echo","l1c1\tl1c2\nl2c1\tl2c2"], tab_split=False), ["l1c1\tl1c2", "l2c1\tl2c2"]) - # self.assertEqual(node.run(["echo","l1\nl2"]), ["l1", "l2"]) #multiline tabsplit self.assertEqual(node.run(["echo","l1c1\tl1c2\nl2c1\tl2c2"], tab_split=True), [['l1c1', 'l1c2'], ['l2c1', 'l2c2']]) - - #escaping (shouldnt be a problem locally, single quotes can be a problem remote via ssh) - s="><`'\"@&$()$bla\\//.*!#test" + #escaping test (shouldnt be a problem locally, single quotes can be a problem remote via ssh) + s="><`'\"@&$()$bla\\/.*!#test _+-={}[]|" self.assertEqual(node.run(["echo",s]), [s]) - #return std err - # self.assertEqual(node.run(["echo","test test"], return_stderr=True), ["test test"]) + #return std err as well, trigger stderr by listing something non existing + (stdout, stderr)=node.run(["ls", "nonexistingfile"], return_stderr=True, valid_exitcodes=[2]) + self.assertEqual(stdout,[]) + self.assertRegex(stderr[0],"nonexistingfile") + + #slow command, make sure things dont exit too early + start_time=time.time() + node.run(["sleep","1"]) + self.assertGreaterEqual(time.time()-start_time,1) + + #input a string and check it via cat + self.assertEqual(node.run(["cat"], input="test"), ["test"]) def test_basicslocal(self): @@ -47,17 +56,6 @@ class TestExecuteNode(unittest.TestCase): self.basics(node) - # def test_remoteecho(self): - # node=ExecuteNode(ssh_to="localhost", debug_output=True) - # self.assertEqual(node.run(["echo","test"]), ["test"]) - - # def test_exitlocal(self): - # node=ExecuteNode(debug_output=True) - - # def test_exitremote(self): - # node=ExecuteNode(ssh_to="localhost", debug_output=True) - # with self.assertRaises(subprocess.CalledProcessError): - # self.remote1.run(["false"]) diff --git a/bin/zfs-autobackup b/bin/zfs-autobackup index 5a47a0e..a605c59 100755 --- a/bin/zfs-autobackup +++ b/bin/zfs-autobackup @@ -378,7 +378,10 @@ class ExecuteNode: #Note: make streaming? if isinstance(input,str) or type(input)=='unicode': - p.stdin.write(input) + p.stdin.write(input.encode('utf-8')) + + if p.stdin: + p.stdin.close() #return pipe if pipe: