Skip to content

Commit

Permalink
Minor fixes for sections
Browse files Browse the repository at this point in the history
* Name all sections "robotmk_..."
* Use null character as separator
* Only report configuration if deserialization was succesful
  • Loading branch information
jherbel committed Nov 7, 2023
1 parent 2531d30 commit 77eeb9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
40 changes: 13 additions & 27 deletions v2/robotmk/src/bin/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ struct Args {
}

#[derive(Serialize)]
pub struct ConfigError {
config_reading_error: String,
}

#[derive(Serialize)]
pub struct ConfigFileContent {
config_file_content: String,
pub enum ConfigSection {
ReadingError(String),
FileContent(String),
}

fn determine_config_path(arg: Option<Utf8PathBuf>) -> Result<Utf8PathBuf, String> {
Expand All @@ -41,26 +37,17 @@ fn config_path_from_env() -> Result<Utf8PathBuf, String> {
Ok(Utf8PathBuf::from(config_path).join("robotmk.json"))
}

fn report_config_error(message: String) {
let config_error = serde_json::to_string(&ConfigError {
config_reading_error: message,
})
.expect("Unexpected serialization error: ConfigError");
println!("{config_error}");
}

fn report_config_content(content: String) {
let config_content = serde_json::to_string(&ConfigFileContent {
config_file_content: content,
})
.expect("Unexpected serialization error: ConfigFileContent");
println!("{config_content}");
fn report_config_section(section: &ConfigSection) {
let section_serialized =
serde_json::to_string(section).expect("Unexpected serialization error: ConfigSection");
println!("<<<robotmk_config:sep(0)>>>");
println!("{section_serialized}");
}

fn print_sections(sections: &[Section], stdout: &mut impl io::Write) {
// TODO: Test this function.
for section in sections.iter() {
let mut with_header = format!("<<<{}>>>\n{}\n", section.name, section.content);
let mut with_header = format!("<<<{}:sep(0)>>>\n{}\n", section.name, section.content);
if let Host::Piggyback(host) = &section.host {
with_header = format!("<<<<{}>>>>\n{}<<<<>>>>\n", host, with_header);
}
Expand All @@ -70,29 +57,28 @@ fn print_sections(sections: &[Section], stdout: &mut impl io::Write) {

fn main() {
let arguments = Args::parse();
println!("<<<robotmk_v2:sep(10)>>>");
let config_path = match determine_config_path(arguments.config_path) {
Ok(p) => p,
Err(e) => {
report_config_error(e);
report_config_section(&ConfigSection::ReadingError(e));
return;
}
};
let raw = match read_to_string(&config_path) {
Ok(raw) => raw,
Err(e) => {
report_config_error(e.to_string());
report_config_section(&ConfigSection::ReadingError(e.to_string()));
return;
}
};
report_config_content(raw.clone());
let config: Config = match serde_json::from_str(&raw) {
Ok(config) => config,
Err(e) => {
report_config_error(e.to_string());
report_config_section(&ConfigSection::ReadingError(e.to_string()));
return;
}
};
report_config_section(&ConfigSection::FileContent(raw));
let sections = read(config.results_directory, &Locker::new(&config_path, None)).unwrap();
print_sections(&sections, &mut io::stdout());
}
6 changes: 3 additions & 3 deletions v2/robotmk/src/bin/scheduler/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct RCCSetupFailures {

impl WriteSection for RCCSetupFailures {
fn name() -> &'static str {
"rcc_setup_failures"
"robotmk_rcc_setup_failures"
}
}

Expand All @@ -36,7 +36,7 @@ pub struct BuildStates<'a>(&'a HashMap<String, EnvironmentBuildStatus>);

impl WriteSection for BuildStates<'_> {
fn name() -> &'static str {
"environment_build_states"
"robotmk_environment_build_states"
}
}

Expand Down Expand Up @@ -89,7 +89,7 @@ pub struct SuiteExecutionReport {

impl WritePiggybackSection for SuiteExecutionReport {
fn name() -> &'static str {
"suite_execution_report"
"robotmk_suite_execution_report"
}
}

Expand Down

0 comments on commit 77eeb9e

Please sign in to comment.