Skip to content

Commit d990a67

Browse files
committed
Add unit tests for previously untested code paths
jobsh/src/jobfile.rs: Add 16 tests for JobFileSet and JobFile parsing. The JobFileSet struct has complex logic for duplicate name detection, dependency cycle detection, and reference validation that was previously untested. github/database/src/tables/check_run.rs: Add 4 tests for CheckRun::get_dependencies(). This method deserializes JSON dependency data and was not covered by existing enum serialization tests. github/database/src/tables/user.rs: Add 2 tests for UserType::from_github_str(). The error path for invalid GitHub API strings was untested. types/src/config.rs: Add 2 tests for ConfigFileDiag inheritance. The explicit "inherit: true" case and mixed inheritance scenarios were not covered by existing tests.
1 parent cda75fe commit d990a67

File tree

4 files changed

+472
-1
lines changed

4 files changed

+472
-1
lines changed

github/database/src/tables/check_run.rs

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl CheckRunDependency {
216216
*/
217217
#[cfg(test)]
218218
mod test {
219-
use super::CheckRunVariety;
219+
use super::*;
220220
use std::str::FromStr;
221221

222222
const CHECK_RUN_VARIETIES: &'static [(&'static str, CheckRunVariety)] = &[
@@ -239,4 +239,75 @@ mod test {
239239
assert_eq!(CheckRunVariety::from_str(s).unwrap(), *e);
240240
}
241241
}
242+
243+
fn make_check_run(dependencies: Option<serde_json::Value>) -> CheckRun {
244+
CheckRun {
245+
id: CheckRunId::generate(),
246+
check_suite: CheckSuiteId::generate(),
247+
name: "test-run".to_string(),
248+
variety: CheckRunVariety::Basic,
249+
content: None,
250+
config: None,
251+
private: None,
252+
active: true,
253+
flushed: false,
254+
github_id: None,
255+
dependencies: dependencies.map(JsonValue),
256+
}
257+
}
258+
259+
#[test]
260+
fn check_run_get_dependencies_none() {
261+
let cr = make_check_run(None);
262+
let deps = cr.get_dependencies().unwrap();
263+
assert!(deps.is_empty());
264+
}
265+
266+
#[test]
267+
fn check_run_get_dependencies_empty() {
268+
let cr = make_check_run(Some(serde_json::json!({})));
269+
let deps = cr.get_dependencies().unwrap();
270+
assert!(deps.is_empty());
271+
}
272+
273+
#[test]
274+
fn check_run_get_dependencies_single() {
275+
let cr = make_check_run(Some(serde_json::json!({
276+
"build": {
277+
"job": "build-job",
278+
"config": {}
279+
}
280+
})));
281+
let deps = cr.get_dependencies().unwrap();
282+
assert_eq!(deps.len(), 1);
283+
assert_eq!(deps.get("build").unwrap().job(), "build-job");
284+
}
285+
286+
#[test]
287+
fn check_run_get_dependencies_multiple() {
288+
let cr = make_check_run(Some(serde_json::json!({
289+
"build": {
290+
"job": "build-job",
291+
"config": {"copy_outputs": true}
292+
},
293+
"test": {
294+
"job": "test-job",
295+
"config": {}
296+
}
297+
})));
298+
let deps = cr.get_dependencies().unwrap();
299+
assert_eq!(deps.len(), 2);
300+
assert_eq!(deps.get("build").unwrap().job(), "build-job");
301+
assert_eq!(deps.get("test").unwrap().job(), "test-job");
302+
303+
// Verify we can extract config from dependency
304+
#[derive(serde::Deserialize)]
305+
struct DepConfig {
306+
#[serde(default)]
307+
copy_outputs: bool,
308+
}
309+
let build_config: DepConfig =
310+
deps.get("build").unwrap().get_config().unwrap();
311+
assert!(build_config.copy_outputs);
312+
}
242313
}

github/database/src/tables/user.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,34 @@ mod test {
123123
assert_eq!(UserType::from_str(s).unwrap(), *e);
124124
}
125125
}
126+
127+
/*
128+
* Test conversion from GitHub API strings.
129+
*/
130+
const GITHUB_USER_TYPES: &[(&str, UserType)] = &[
131+
("User", UserType::User),
132+
("Bot", UserType::Bot),
133+
("Organization", UserType::Organisation),
134+
];
135+
136+
#[test]
137+
fn user_type_from_github_str() {
138+
for (s, e) in GITHUB_USER_TYPES {
139+
assert_eq!(UserType::from_github_str(s).unwrap(), *e);
140+
}
141+
}
142+
143+
#[test]
144+
fn user_type_from_github_str_invalid() {
145+
let invalid_types = &["user", "bot", "org", "Invalid", "", "Org"];
146+
for invalid in invalid_types {
147+
let err = UserType::from_github_str(invalid).unwrap_err();
148+
assert!(
149+
err.to_string().contains("invalid user type"),
150+
"expected invalid user type error for {:?}, got: {}",
151+
invalid,
152+
err
153+
);
154+
}
155+
}
126156
}

0 commit comments

Comments
 (0)