diff options
author | Alex Crichton <alex@alexcrichton.com> | 2014-09-19 17:34:02 -0700 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2014-09-19 18:00:07 -0700 |
commit | b4a344e1cc48b8cf8e6aa9957b090e73f6f31646 (patch) | |
tree | d0c3910a1483d5f0f49e29add45d596888c2a380 /tests | |
parent | fb3186e7285977d88babc4ce13bf93a6bc76ccb5 (diff) | |
download | ssh2-rs-b4a344e1cc48b8cf8e6aa9957b090e73f6f31646.zip |
Bind SFTP functionality.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sftp.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/sftp.rs b/tests/sftp.rs index f600abd..1abf02b 100644 --- a/tests/sftp.rs +++ b/tests/sftp.rs @@ -1,5 +1,40 @@ +use std::io::{mod, fs, File, TempDir}; +use std::io::fs::PathExtensions; + #[test] fn smoke() { let (_tcp, sess) = ::authed_session(); sess.sftp().unwrap(); } + +#[test] +fn ops() { + let td = TempDir::new("foo").unwrap(); + File::create(&td.path().join("foo")).unwrap(); + fs::mkdir(&td.path().join("bar"), io::UserDir).unwrap(); + + let (_tcp, sess) = ::authed_session(); + let sftp = sess.sftp().unwrap(); + sftp.opendir(&td.path().join("bar")).unwrap(); + let mut foo = sftp.open(&td.path().join("foo")).unwrap(); + sftp.mkdir(&td.path().join("bar2"), io::UserDir).unwrap(); + assert!(td.path().join("bar2").is_dir()); + sftp.rmdir(&td.path().join("bar2")).unwrap(); + + sftp.create(&td.path().join("foo5")).unwrap().write(b"foo").unwrap(); + assert_eq!(File::open(&td.path().join("foo5")).read_to_end().unwrap(), + b"foo".to_vec()); + + assert_eq!(sftp.stat(&td.path().join("foo")).unwrap().size, Some(0)); + assert_eq!(foo.read_to_end().unwrap(), Vec::new()); + + sftp.symlink(&td.path().join("foo"), + &td.path().join("foo2")).unwrap(); + let readlink = sftp.readlink(&td.path().join("foo2")).unwrap(); + assert!(readlink == td.path().join("foo")); + let realpath = sftp.realpath(&td.path().join("foo2")).unwrap(); + assert!(realpath == td.path().join("foo")); + + let files = sftp.readdir(td.path()).unwrap(); + assert_eq!(files.len(), 4); +} |