mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-04-13 22:47:12 +03:00
more unit tests and fixes
This commit is contained in:
parent
04971f2f29
commit
55f491915a
@ -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"])
|
||||
|
||||
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user