Skip to content

Commit ff3a2f5

Browse files
committed
move transport tests to API tests
1 parent bc32d39 commit ff3a2f5

File tree

3 files changed

+49
-40
lines changed

3 files changed

+49
-40
lines changed

src/transport/mod.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,6 @@ pub struct ListDirNames {
150150
///
151151
/// Locations can be parsed from strings. At present the only supported form is an absolute
152152
/// or relative filename.
153-
/// ```
154-
/// use std::str::FromStr;
155-
/// use conserve::transport::Location;
156-
///
157-
/// let location: Location = Location::from_str("/backup/example").unwrap();
158-
/// let transport = location.open();
159-
/// ```
160153
#[derive(Debug, Eq, PartialEq)]
161154
pub enum Location {
162155
/// A local directory.
@@ -167,14 +160,6 @@ impl Location {
167160
/// Open a Transport that can read and write this location.
168161
///
169162
/// The location need not already exist.
170-
///
171-
/// ```
172-
/// use std::path::PathBuf;
173-
/// use conserve::transport::Location;
174-
///
175-
/// let location = Location::Local("/backup".to_owned().into());
176-
/// let transport = location.open().unwrap();
177-
/// ```
178163
pub fn open(&self) -> Result<Box<dyn Transport>> {
179164
match self {
180165
Location::Local(pathbuf) => Ok(Box::new(local::LocalTransport::new(&pathbuf))),
@@ -190,28 +175,3 @@ impl FromStr for Location {
190175
Ok(Location::Local(s.into()))
191176
}
192177
}
193-
194-
#[cfg(test)]
195-
mod test {
196-
use assert_fs::prelude::*;
197-
198-
use super::*;
199-
use crate::transport::local::LocalTransport;
200-
201-
#[test]
202-
fn list_dir_names() {
203-
let temp = assert_fs::TempDir::new().unwrap();
204-
temp.child("a dir").create_dir_all().unwrap();
205-
temp.child("a file").touch().unwrap();
206-
temp.child("another file").touch().unwrap();
207-
208-
let transport = LocalTransport::new(&temp.path());
209-
210-
let ListDirNames { mut files, dirs } = transport.list_dir_names("").unwrap();
211-
assert_eq!(dirs, ["a dir"]);
212-
files.sort();
213-
assert_eq!(files, ["a file", "another file"]);
214-
215-
temp.close().unwrap();
216-
}
217-
}

tests/api/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ mod delete;
2020
mod gc;
2121
mod old_archives;
2222
mod restore;
23+
mod transport;

tests/api/transport.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2021 Martin Pool.
2+
3+
// This program is free software; you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation; either version 2 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
13+
use assert_fs::prelude::*;
14+
15+
use conserve::transport::{ListDirNames, Location};
16+
17+
#[test]
18+
fn open_local() {
19+
let location = Location::Local("/backup".to_owned().into());
20+
let _transport = location.open().unwrap();
21+
}
22+
23+
#[test]
24+
fn parse_location() {
25+
use conserve::transport::Location;
26+
use std::str::FromStr;
27+
let location: Location = Location::from_str("/backup/example").unwrap();
28+
let _transport = location.open();
29+
}
30+
31+
#[test]
32+
fn list_dir_names() {
33+
let temp = assert_fs::TempDir::new().unwrap();
34+
temp.child("a dir").create_dir_all().unwrap();
35+
temp.child("a file").touch().unwrap();
36+
temp.child("another file").touch().unwrap();
37+
38+
let transport = Location::Local((&temp.path()).to_path_buf())
39+
.open()
40+
.unwrap();
41+
42+
let ListDirNames { mut files, dirs } = transport.list_dir_names("").unwrap();
43+
assert_eq!(dirs, ["a dir"]);
44+
files.sort();
45+
assert_eq!(files, ["a file", "another file"]);
46+
47+
temp.close().unwrap();
48+
}

0 commit comments

Comments
 (0)