Create a TestConfig struct to separate setup
I was about to copy-paste the entire body of the attach_file_exists test function into the attach_file_missing function. The only difference is the file that they upload -- or don't, in the second case. I could make a try-file-upload function and pass it many different files, but I don't think I need that. Instead, I'll separate the test setup from the test sequence itself.
This commit is contained in:
@@ -50,6 +50,43 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn attach_file_exists() {
|
async fn attach_file_exists() {
|
||||||
|
let conf = TestConfig::new();
|
||||||
|
let release_candidates =
|
||||||
|
crate::api::release::list_releases(
|
||||||
|
&conf.client,
|
||||||
|
&conf.server,
|
||||||
|
&conf.repo
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Failed to get releases. Pre-conditions unmet, aborting test!");
|
||||||
|
|
||||||
|
let release = match_release_by_tag(&conf.release_tag, release_candidates)
|
||||||
|
.expect("Failed to select matching release. Pre-conditions unmet, aborting test!");
|
||||||
|
|
||||||
|
let api_result = super::create_release_attachment(
|
||||||
|
&conf.client,
|
||||||
|
&conf.server,
|
||||||
|
&conf.repo,
|
||||||
|
release.id,
|
||||||
|
vec![String::from("Cargo.toml")],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn attach_file_missing() {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TestConfig {
|
||||||
|
server: String,
|
||||||
|
repo: String,
|
||||||
|
release_tag: String,
|
||||||
|
client: reqwest::Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TestConfig {
|
||||||
|
fn new() -> Self {
|
||||||
let server = std::env::var("TEST_GITEA_SERVER")
|
let server = std::env::var("TEST_GITEA_SERVER")
|
||||||
.expect("Must set server address in env var \"TEST_GITEA_SERVER\"");
|
.expect("Must set server address in env var \"TEST_GITEA_SERVER\"");
|
||||||
let repo = std::env::var("TEST_GITEA_REPO")
|
let repo = std::env::var("TEST_GITEA_REPO")
|
||||||
@@ -75,31 +112,13 @@ mod tests {
|
|||||||
.build()
|
.build()
|
||||||
.expect("Failed to build reqwest::Client.");
|
.expect("Failed to build reqwest::Client.");
|
||||||
|
|
||||||
let release_candidates =
|
return Self {
|
||||||
crate::api::release::list_releases(
|
server,
|
||||||
&client,
|
repo,
|
||||||
&server,
|
release_tag,
|
||||||
&repo
|
client
|
||||||
)
|
};
|
||||||
.await
|
|
||||||
.expect("Failed to get releases. Pre-conditions unmet, aborting test!");
|
|
||||||
|
|
||||||
let release = match_release_by_tag(&release_tag, release_candidates)
|
|
||||||
.expect("Failed to select matching release. Pre-conditions unmet, aborting test!");
|
|
||||||
|
|
||||||
let api_result = super::create_release_attachment(
|
|
||||||
&client,
|
|
||||||
&server,
|
|
||||||
&repo,
|
|
||||||
release.id,
|
|
||||||
vec![String::from("Cargo.toml")],
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn attach_file_missing() {
|
|
||||||
todo!();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing utils
|
// Testing utils
|
||||||
|
|||||||
Reference in New Issue
Block a user