Struct rfs_tester::rfs::fs_tester::FsTester[][src]

pub struct FsTester {
    pub config: Config,
    pub base_dir: String,
}

File System Tester used to create some configured structure in directory with files and links to them. FsTester can start custom test closure and remove fs structure after testing complete or fail.

Fields

config: Configbase_dir: String

Implementations

impl FsTester[src]

pub fn parse_config(config_str: &str) -> Result<Config, Box<dyn Error>>[src]

Config parser config can be string in yaml or json format:

Example for yaml

let simple_conf_str = "---
  - directory:
      name: test
      content:
        - file:
            name: test.txt
            content:
              inline_bytes:            
                - 116            
                - 101            
                - 115            
                - 116            
";

Example for json

let simple_conf_str = 
  "[{\"directory\":{\"name\":\"test\",\"content\":[{\"file\":{\"name\":\"test.txt\",\"content\":{\"inline_bytes\":[116,101,115,116]}}}]}}]";
 

pub fn new(config_str: &str, start_point: &str) -> FsTester[src]

create the test directory, files and link set config_str - configuration of test directory in yaml or json format start_point - directory name where will create testing directory, it should presents in FS.

pub fn perform_fs_test<F>(&self, test_proc: F) where
    F: Fn(&str) -> Result<()>, 
[src]

Start test_proc function. The test unit can define as closure parameter of perform_fs_test. The dirname closure parameter is name of generated temporary test directory which contains fs units set. We cannot know full name before testing start because it has random number in the end of name. FsTester has known it after instance build.

Example

use std::fs;
const YAML_DIR_WITH_TEST_FILE_FROM_CARGO_TOML: &str = "---
- directory:
    name: test
    content:
      - file:
          name: test_from_cargo.toml
          content:
            original_file: Cargo.toml
 ";

let tester = FsTester::new(YAML_DIR_WITH_TEST_FILE_FROM_CARGO_TOML, ".");
tester.perform_fs_test(|dirname| {
//                      ^^^^^^^ name with appended random at the end of name 
  let inner_file_name = format!("{}/{}", dirname, "test_from_cargo.toml");
  let metadata = fs::metadata(inner_file_name)?;
   
  assert!(metadata.len() > 0);
  Ok(())
});
   

Trait Implementations

impl Drop for FsTester[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,