Skip to content

Commit

Permalink
test: add Config::test() factory
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Dec 4, 2023
1 parent de97b41 commit 95fbdf0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 35 deletions.
19 changes: 3 additions & 16 deletions src/ci_provider/buildkite/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ impl CIProvider for BuildkiteProvider {
mod tests {
use insta::assert_json_snapshot;
use temp_env::{with_var, with_vars};
use url::Url;

use super::*;

Expand Down Expand Up @@ -222,12 +221,8 @@ mod tests {
],
|| {
let config = Config {
command: "upload".into(),
skip_setup: false,
skip_upload: false,
token: Some("token".into()),
upload_url: Url::parse("https://example.com").unwrap(),
working_directory: Some(".".into()),
..Config::test()
};
let provider = BuildkiteProvider::try_from(&config).unwrap();

Expand Down Expand Up @@ -266,12 +261,8 @@ mod tests {
],
|| {
let config = Config {
command: "upload".into(),
skip_setup: false,
skip_upload: false,
token: Some("token".into()),
upload_url: Url::parse("https://example.com").unwrap(),
working_directory: Some(".".into()),
..Config::test()
};
let provider = BuildkiteProvider::try_from(&config).unwrap();

Expand Down Expand Up @@ -310,12 +301,8 @@ mod tests {
],
|| {
let config = Config {
command: "upload".into(),
skip_setup: false,
skip_upload: false,
token: Some("token".into()),
upload_url: Url::parse("https://example.com").unwrap(),
working_directory: Some(".".into()),
..Config::test()
};
let provider = BuildkiteProvider::try_from(&config).unwrap();
let upload_metadata = provider.get_upload_metadata(&config, "abc123").unwrap();
Expand Down
19 changes: 3 additions & 16 deletions src/ci_provider/github_actions/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ impl CIProvider for GitHubActionsProvider {
mod tests {
use insta::assert_json_snapshot;
use temp_env::{with_var, with_vars};
use url::Url;

use super::*;

Expand Down Expand Up @@ -198,12 +197,8 @@ mod tests {
],
|| {
let config = Config {
command: "upload".into(),
skip_setup: false,
skip_upload: false,
token: Some("token".into()),
upload_url: Url::parse("https://example.com").unwrap(),
working_directory: Some(".".into()),
..Config::test()
};
let github_actions_provider = GitHubActionsProvider::try_from(&config).unwrap();
assert_eq!(github_actions_provider.owner, "owner");
Expand Down Expand Up @@ -264,12 +259,8 @@ mod tests {
],
|| {
let config = Config {
command: "upload".into(),
skip_setup: false,
skip_upload: false,
token: Some("token".into()),
upload_url: Url::parse("https://example.com").unwrap(),
working_directory: Some(".".into()),
..Config::test()
};
let github_actions_provider = GitHubActionsProvider::try_from(&config).unwrap();
let upload_metadata = github_actions_provider
Expand Down Expand Up @@ -318,12 +309,8 @@ mod tests {
],
|| {
let config = Config {
command: "upload".into(),
skip_setup: false,
skip_upload: false,
token: Some("token".into()),
upload_url: Url::parse("https://example.com").unwrap(),
working_directory: Some(".".into()),
..Config::test()
};
let github_actions_provider = GitHubActionsProvider::try_from(&config).unwrap();
let upload_metadata = github_actions_provider
Expand Down
15 changes: 15 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ pub struct Config {
pub skip_setup: bool,
}

#[cfg(test)]
impl Config {
/// Constructs a new `Config` with default values for testing purposes
pub fn test() -> Self {
Self {
upload_url: Url::parse(DEFAULT_UPLOAD_URL).unwrap(),
token: None,
working_directory: None,
command: "".into(),
skip_upload: false,
skip_setup: false,
}
}
}

const DEFAULT_UPLOAD_URL: &str = "https://api.codspeed.io/upload";

impl TryFrom<AppArgs> for Config {
Expand Down
4 changes: 1 addition & 3 deletions src/uploader/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ mod tests {
let config = Config {
command: "pytest tests/ --codspeed".into(),
upload_url: Url::parse("change me").unwrap(),
skip_setup: false,
skip_upload: false,
token: Some("change me".into()),
working_directory: None,
..Config::test()
};
let run_data = RunData {
profile_folder: PathBuf::from(format!(
Expand Down

0 comments on commit 95fbdf0

Please sign in to comment.