Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Commit 3e55732

Browse files
committed
add mockedExecutables field to Protocols parsing
1 parent 377a011 commit 3e55732

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

src/protocol/mod.rs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ pub struct Protocols {
369369
pub protocols: Vec<Protocol>,
370370
pub unmocked_commands: Vec<PathBuf>,
371371
pub interpreter: Option<PathBuf>,
372+
pub mocked_executables: Vec<PathBuf>,
372373
}
373374

374375
impl Protocols {
@@ -377,6 +378,7 @@ impl Protocols {
377378
protocols,
378379
unmocked_commands: vec![],
379380
interpreter: None,
381+
mocked_executables: vec![],
380382
}
381383
}
382384

@@ -405,6 +407,16 @@ impl Protocols {
405407
Ok(())
406408
}
407409

410+
fn add_mocked_executables(&mut self, object: &Hash) -> R<()> {
411+
if let Ok(mocked_executables) = object.expect_field("mockedExecutables") {
412+
for mocked_executable in mocked_executables.expect_array()? {
413+
self.mocked_executables
414+
.push(PathBuf::from(mocked_executable.expect_str()?));
415+
}
416+
}
417+
Ok(())
418+
}
419+
408420
fn parse(yaml: Yaml) -> R<Protocols> {
409421
Ok(match &yaml {
410422
Yaml::Array(array) => Protocols::from_array(&array)?,
@@ -413,10 +425,19 @@ impl Protocols {
413425
object.expect_field("protocol"),
414426
) {
415427
(Ok(protocols), _) => {
416-
check_keys(&["protocols", "interpreter", "unmockedCommands"], object)?;
428+
check_keys(
429+
&[
430+
"protocols",
431+
"interpreter",
432+
"unmockedCommands",
433+
"mockedExecutables",
434+
],
435+
object,
436+
)?;
417437
let mut protocols = Protocols::from_array(protocols.expect_array()?)?;
418438
protocols.add_unmocked_commands(object)?;
419439
protocols.add_interpreter(object)?;
440+
protocols.add_mocked_executables(object)?;
420441
protocols
421442
}
422443
(Err(_), Ok(_)) => Protocols::new(vec![Protocol::from_object(&object)?]),
@@ -559,7 +580,8 @@ mod load {
559580
format!(
560581
"error in {}.protocols.yaml: \
561582
unexpected field 'foo', \
562-
possible values: 'protocols', 'interpreter', 'unmockedCommands'",
583+
possible values: 'protocols', 'interpreter', 'unmockedCommands', \
584+
'mockedExecutables'",
563585
path_to_string(&tempfile.path())?
564586
)
565587
);
@@ -999,7 +1021,27 @@ mod load {
9991021
)?
10001022
.mocked_files
10011023
.map(|path| path.to_string_lossy().to_string()),
1002-
vec![("/foo")]
1024+
vec!["/foo"]
1025+
);
1026+
Ok(())
1027+
}
1028+
1029+
#[test]
1030+
fn allows_to_specify_mocked_executables() -> R<()> {
1031+
let tempfile = TempFile::new()?;
1032+
assert_eq!(
1033+
test_parse(
1034+
&tempfile,
1035+
r"
1036+
|protocols:
1037+
| - protocol: []
1038+
|mockedExecutables:
1039+
| - foo
1040+
"
1041+
)?
1042+
.mocked_executables
1043+
.map(|path| path.to_string_lossy().to_string()),
1044+
vec!["foo"]
10031045
);
10041046
Ok(())
10051047
}

src/recorder/hole_recorder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub fn run_against_protocols(
112112
protocols,
113113
unmocked_commands,
114114
interpreter,
115+
..
115116
}: Protocols,
116117
) -> R<ExitCode> {
117118
let results = ProtocolResult::collect_results(

src/recorder/protocol_result.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl ProtocolResult {
100100
protocols: results.iter().map(|result| result.get_protocol()).collect(),
101101
unmocked_commands,
102102
interpreter: None,
103+
mocked_executables: vec![],
103104
}
104105
.serialize()?,
105106
)?;

0 commit comments

Comments
 (0)