Crate test_with

Source
Expand description

test_with provides env, file, path, http, https, icmp, tcp, root, group, user, mem, swap, cpu_core, phy_core, executable, timezone macros to help you run test case only with the condition is fulfilled. If the #[test] is absent for the test case, #[test_with] will add it to the test case automatically.

This crate help you easier make integrating test case and has a good cargo summary on CI server, and will not affect on your binary output when you dependent it as dev-dependency as following.

[dev-dependencies]
test-with = "*"

All features will be opt-in default feature, so this crate will be easier to use, if you using a CI server with really limitation resource and want this crate as slim as possible, you can select the feature you want as following.

[dev-dependencies]
test-with = { version = "*", default-features = false, features = ["net"] }

The solution to have a real runtime condition check, we need to put the test as normal function as an example, then use cargo run --example The test-with need be included as normal dependency with runtime feature. And also include the libtest-with with corresponding features in Cargo.toml runner and module are for the basic skeleton of the test runner. runtime_env, runtime_no_env, runtime_file, runtime_path, runtime_http, runtime_https, runtime_icmp, runtime_tcp, runtime_root, runtime_group, runtime_user, runtime_mem, runtime_free_mem, runtime_available_mem, runtime_swap, runtime_free_swap, [macro@runtime_available_swap], runtime_cpu_core, [macro@runtime_phy_core], runtime_executable, runtime_timezone and runtime_ignore_if are used to transform a normal function to a testcase.

[dependencies]
test-with = { version = "*", default-features = false, features = ["runtime"] }
libtest-with = { version = "0.8.1-7", features = ["net", "resource", "user", "executable", "timezone"] }
// write as example in examples/*rs
test_with::runner!(env);
#[test_with::module]
mod env {
#[test_with::runtime_env(PWD)]
fn test_works() {
    assert!(true);
    }
}

Macros§

runner
Provide a test runner and test on each module
tokio_runner

Attribute Macros§

cpu_core
Run test case when cpu core enough
env
Run test case when the environment variable is set.
executable
Run test case when the executables exist.
file
Run test case when the file exist.
group
Run test case when runner in group
http
Run test case when the http service exist.
https
Run test case when the https service exist.
icmp
Run test case when the server online. Please make sure the role of test case runner have capability to open socket
lock
Run test case one by one when the lock is acquired It will automatically implement a file lock for the test case to prevent it run in the same time. Also, you can pass the second parameter to specific the waiting seconds, default will be 60 seconds.
mem
Run test case when memory size enough
module
Help each function with #[test_with::runtime_*] in the module can register to run Also you can set up a mock instance for all of the test in the module
no_env
Ignore test case when the environment variable is set.
path
Run test case when the path(file or folder) exist.
phy_core
Run test case when physical cpu core enough
root
Run test case when runner is root
runtime_available_mem
Run test case when the example running and available memory size enough
runtime_cpu_core
Run test case when cpu core enough
runtime_env
Run test case when the example running and the environment variable is set.
runtime_executable
Run test case when the executable existing
runtime_file
Run test case when the example running and the file exist.
runtime_free_mem
Run test case when the example running and free memory size enough
runtime_free_swap
Run test case when the example running and free swap enough
runtime_group
Run test case when runner in group
runtime_http
Run test case when the example running and the http service exist.
runtime_https
Run test case when the example running and the http service exist.
runtime_icmp
Run test case when the example running and the server online. Please make sure the role of test case runner have capability to open socket
runtime_ignore_if
Ignore test case when function return some reason The function should be fn() -> Option<String>
runtime_mem
Run test case when the example running and memory size enough
runtime_no_env
Ignore test case when the example running and the environment variable is set.
runtime_path
Run test case when the example running and the path(file or folder) exist.
runtime_phy_cpu_core
Run test case when physical core enough
runtime_root
Run test case when runner is root
runtime_swap
Run test case when the example running and swap enough
runtime_tcp
Run test case when the example running and socket connected
runtime_timezone
Run test case when the example running within specific timzones.
runtime_user
Run test case when runner is specific user
swap
Run test case when swap size enough
tcp
Run test case when socket connected
timezone
Run test case when the timezone is expected.
user
Run test case when runner is specific user