#[test]
fn test_fix_success() {
let mut mock_ssh_config = MockSshConfigTrait::new();
mock_ssh_config
.expect_session()
.with(eq("host"))
.return_once(|_| {
let mut mock_ssh_session = MockSshSessionTrait::new();
mock_ssh_session
.expect_exec()
.times(4)
.with(eq("chown -c uid:gid ~uid 2>&1"))
.with(eq("chown -c -R uid:gid ~uid/website 2>&1"))
.with(eq(
"find ~uid/website -type d -print0 | xargs -0 chmod -c 2750 2>&1",
))
.with(eq(
"find ~uid/website -type f -print0 | xargs -0 chmod -c 0640 2>&1",
))
.returning(|_| Ok("".to_string()))
.returning(|_| Ok("".to_string()))
.returning(|_| Ok("".to_string()))
.returning(|_| Ok("".to_string()));
Ok(Arc::new(mock_ssh_session) as DynSshSession)
});
let model = PermsfixModel {
ssh_config: Arc::new(mock_ssh_config) as DynSshConfig,
};
let result = model.fix("host", "website", "uid", "gid").unwrap();
assert_eq!(result, "".to_string());
}
In this test, I'm passing in mock_ssh_config in PermsFixModel, with the expectation that it will produce a mock_ssh_session, which later on will be expected to execute some commands.
With my limited experience, the result is not what I expect. I expect SshConfig::session() to be mocked and return the given mock. However, the method is actually invoked. I have asserted this with a simple debiug statement in SshConfig::session().
What am I doing wrong here? Is there a better approach?
Thanks a bunch,
Samy