Skip to content

Commit f470b0a

Browse files
authored
Merge pull request #470 from Kobzol/test-config
Add test for making sure that example config is valid
2 parents d427d93 + 8210a6d commit f470b0a

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/config.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ pub struct RepositoryConfig {
3838
pub merge_queue_enabled: bool,
3939
}
4040

41+
/// Load a repository config from TOML.
42+
pub fn deserialize_config(text: &str) -> Result<RepositoryConfig, toml::de::Error> {
43+
toml::from_str(text)
44+
}
45+
4146
fn default_timeout() -> Duration {
4247
Duration::from_secs(3600)
4348
}
@@ -150,10 +155,10 @@ where
150155

151156
#[cfg(test)]
152157
mod tests {
158+
use crate::config::{RepositoryConfig, default_timeout, deserialize_config};
159+
use std::path::Path;
153160
use std::{collections::BTreeMap, time::Duration};
154161

155-
use crate::config::{RepositoryConfig, default_timeout};
156-
157162
#[test]
158163
fn deserialize_empty() {
159164
let content = "";
@@ -274,7 +279,16 @@ approved = ["foo"]
274279
load_config(content);
275280
}
276281

282+
#[test]
283+
fn load_example_config() {
284+
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("rust-bors.example.toml");
285+
let config = std::fs::read_to_string(path)
286+
.expect("Cannot load example bors config from repository root");
287+
deserialize_config(&config)
288+
.expect("Cannot deserialize example bors config from `rust-bors.example.toml`");
289+
}
290+
277291
fn load_config(config: &str) -> RepositoryConfig {
278-
toml::from_str(config).unwrap()
292+
deserialize_config(config).expect("Cannot deserialize repository config")
279293
}
280294
}

src/github/api/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use tracing::log;
99

1010
use crate::bors::event::PullRequestComment;
1111
use crate::bors::{Comment, WorkflowRun};
12-
use crate::config::{CONFIG_FILE_PATH, RepositoryConfig};
12+
use crate::config::{CONFIG_FILE_PATH, RepositoryConfig, deserialize_config};
1313
use crate::database::WorkflowStatus;
1414
use crate::github::api::operations::{
1515
BranchUpdateError, ForcePush, MergeError, create_check_run, merge_branches,
@@ -83,7 +83,7 @@ impl GithubRepositoryClient {
8383
.ok_or_else(|| anyhow::anyhow!("Configuration file not found"))
8484
.and_then(|content| {
8585
let config: RepositoryConfig =
86-
toml::from_str(&content).map_err(|error| {
86+
deserialize_config(&content).map_err(|error| {
8787
anyhow::anyhow!(
8888
"Could not deserialize repository config: {error:?}"
8989
)

0 commit comments

Comments
 (0)