2011-05-31 21:33:00 +00:00
|
|
|
import fudge
|
|
|
|
import fudge.inspector
|
|
|
|
|
|
|
|
from .. import remote
|
2011-06-03 21:44:29 +00:00
|
|
|
from ..run import RemoteProcess
|
2011-05-31 21:33:00 +00:00
|
|
|
|
|
|
|
|
2013-09-30 18:30:28 +00:00
|
|
|
class TestRemote(object):
|
|
|
|
def test_shortname(self):
|
|
|
|
r = remote.Remote(
|
|
|
|
name='jdoe@xyzzy.example.com',
|
|
|
|
shortname='xyz',
|
|
|
|
ssh=fudge.Fake('SSHConnection'),
|
|
|
|
)
|
|
|
|
assert r.shortname == 'xyz'
|
2014-05-09 16:27:23 +00:00
|
|
|
assert str(r) == 'jdoe@xyzzy.example.com'
|
2013-09-30 18:30:28 +00:00
|
|
|
|
|
|
|
def test_shortname_default(self):
|
|
|
|
r = remote.Remote(
|
|
|
|
name='jdoe@xyzzy.example.com',
|
|
|
|
ssh=fudge.Fake('SSHConnection'),
|
|
|
|
)
|
2014-05-09 16:27:23 +00:00
|
|
|
assert r.shortname == 'xyzzy'
|
2013-09-30 18:30:28 +00:00
|
|
|
assert str(r) == 'jdoe@xyzzy.example.com'
|
|
|
|
|
|
|
|
@fudge.with_fakes
|
|
|
|
def test_run(self):
|
|
|
|
fudge.clear_expectations()
|
|
|
|
ssh = fudge.Fake('SSHConnection')
|
2014-05-30 16:59:09 +00:00
|
|
|
ssh.expects('get_transport').returns_fake().expects('getpeername')\
|
|
|
|
.returns(('name', 22))
|
2013-09-30 18:30:28 +00:00
|
|
|
run = fudge.Fake('run')
|
|
|
|
args = [
|
|
|
|
'something',
|
|
|
|
'more',
|
|
|
|
]
|
|
|
|
foo = object()
|
|
|
|
ret = RemoteProcess(
|
2014-05-30 16:59:09 +00:00
|
|
|
client=ssh,
|
|
|
|
args='fakey',
|
2013-09-30 18:30:28 +00:00
|
|
|
)
|
2014-05-09 16:30:13 +00:00
|
|
|
r = remote.Remote(name='jdoe@xyzzy.example.com', ssh=ssh)
|
2013-09-30 18:30:28 +00:00
|
|
|
run.expects_call().with_args(
|
|
|
|
client=fudge.inspector.arg.passes_test(lambda v: v is ssh),
|
|
|
|
args=fudge.inspector.arg.passes_test(lambda v: v is args),
|
|
|
|
foo=fudge.inspector.arg.passes_test(lambda v: v is foo),
|
2014-05-09 16:30:13 +00:00
|
|
|
name=r.shortname,
|
2013-09-30 18:30:28 +00:00
|
|
|
).returns(ret)
|
|
|
|
# monkey patch ook ook
|
|
|
|
r._runner = run
|
|
|
|
got = r.run(
|
|
|
|
args=args,
|
|
|
|
foo=foo,
|
|
|
|
)
|
|
|
|
assert got is ret
|
|
|
|
assert got.remote is r
|