Add test for missing and example config file and helper methods

This commit is contained in:
Matthias 2023-03-01 20:55:22 +01:00 committed by Matthias Endler
parent 387766322d
commit 19976cd9e7

View file

@ -51,12 +51,17 @@ mod cli {
Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Couldn't get cargo package name")
}
/// Helper function to get the path to the fixtures directory.
fn fixtures_path() -> PathBuf {
/// Helper function to get the root path of the project.
fn root_path() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("fixtures")
.to_path_buf()
}
/// Helper function to get the path to the fixtures directory.
fn fixtures_path() -> PathBuf {
root_path().join("fixtures")
}
#[derive(Default)]
@ -634,6 +639,33 @@ mod cli {
.failure();
}
#[tokio::test]
async fn test_missing_config_error() {
let mock_server = mock_server!(StatusCode::OK);
let mut cmd = main_command();
cmd.arg("--config")
.arg("config.does.not.exist.toml")
.arg("-")
.write_stdin(mock_server.uri())
.env_clear()
.assert()
.failure();
}
#[tokio::test]
async fn test_config_example() {
let mock_server = mock_server!(StatusCode::OK);
let config = root_path().join("lychee.example.toml");
let mut cmd = main_command();
cmd.arg("--config")
.arg(config)
.arg("-")
.write_stdin(mock_server.uri())
.env_clear()
.assert()
.success();
}
#[tokio::test]
async fn test_config_smoketest() {
let mock_server = mock_server!(StatusCode::OK);