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:
2025-06-04 11:30:55 -05:00
parent e7e8a2871b
commit 098f967174

View File

@@ -50,6 +50,43 @@ mod tests {
#[tokio::test]
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")
.expect("Must set server address in env var \"TEST_GITEA_SERVER\"");
let repo = std::env::var("TEST_GITEA_REPO")
@@ -75,31 +112,13 @@ mod tests {
.build()
.expect("Failed to build reqwest::Client.");
let release_candidates =
crate::api::release::list_releases(
&client,
&server,
&repo
)
.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;
return Self {
server,
repo,
release_tag,
client
};
}
#[test]
fn attach_file_missing() {
todo!();
}
// Testing utils