Skip to content

Commit

Permalink
remove annoying nulls
Browse files Browse the repository at this point in the history
- now that the tests pass, remove the nulls from the json output
- while the spec says this is ok, it just makes the tests unnecessarily
  verbose

Signed-off-by: mimir-d <[email protected]>
  • Loading branch information
mimir-d committed Oct 9, 2024
1 parent f4caa17 commit b5f9fe2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 205 deletions.
5 changes: 0 additions & 5 deletions src/output/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ impl ConfigBuilder {

pub trait TimestampProvider {
fn now(&self) -> chrono::DateTime<chrono_tz::Tz>;

fn to_string(&self) -> String {
self.now()
.to_rfc3339_opts(chrono::SecondsFormat::Millis, true)
}
}

struct ConfiguredTzProvider {
Expand Down
34 changes: 9 additions & 25 deletions src/output/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ impl ErrorBuilder {
#[cfg(test)]
mod tests {
use anyhow::Result;

use assert_json_diff::assert_json_include;
use assert_json_diff::assert_json_eq;

use super::*;
use crate::output as tv;
Expand Down Expand Up @@ -140,45 +139,30 @@ mod tests {
"message": "message",
"softwareInfoIds": [
{
"computerSystem": null,
"name": "name",
"revision": null,
"softwareInfoId":
"software_id",
"softwareType": null,
"version": null
"softwareInfoId": "software_id",
},
{
"computerSystem": null,
"name": "name",
"revision": null,
"softwareInfoId":
"software_id",
"softwareType": null,
"version": null
"softwareInfoId": "software_id",
}
],
"sourceLocation": {"file": "file.rs", "line": 1},
"sourceLocation": {
"file": "file.rs",
"line": 1
},
"symptom": "symptom"
});
let expected_step = serde_json::json!({
"message": "message",
"softwareInfoIds": [
{
"computerSystem": null,
"name": "name",
"revision": null,
"softwareInfoId": "software_id",
"softwareType": null,
"version": null
},
{
"computerSystem": null,
"name": "name",
"revision": null,
"softwareInfoId": "software_id",
"softwareType": null,
"version": null
}
],
"sourceLocation": {"file":"file.rs","line":1},
Expand All @@ -195,11 +179,11 @@ mod tests {

let spec_error = error.to_artifact();
let actual = serde_json::json!(spec_error);
assert_json_include!(actual: actual, expected: &expected_run);
assert_json_eq!(actual, expected_run);

let spec_error = error.to_artifact();
let actual = serde_json::json!(spec_error);
assert_json_include!(actual: actual, expected: &expected_step);
assert_json_eq!(actual, expected_step);

Ok(())
}
Expand Down
48 changes: 48 additions & 0 deletions src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ pub struct TestRunStart {
#[serde(rename = "dutInfo")]
pub dut_info: DutInfo,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "metadata")]
pub metadata: Option<Map<String, Value>>,
}
Expand All @@ -288,18 +289,23 @@ pub struct DutInfo {
#[serde(rename = "dutInfoId")]
pub id: String,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "name")]
pub name: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "platformInfos")]
pub platform_infos: Option<Vec<PlatformInfo>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "softwareInfos")]
pub software_infos: Option<Vec<SoftwareInfo>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "hardwareInfos")]
pub hardware_infos: Option<Vec<HardwareInfo>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "metadata")]
pub metadata: Option<Map<String, Value>>,
}
Expand Down Expand Up @@ -330,15 +336,19 @@ pub struct SoftwareInfo {
#[serde(rename = "name")]
pub name: String,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "version")]
pub version: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "revision")]
pub revision: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "softwareType")]
pub software_type: Option<SoftwareType>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "computerSystem")]
pub computer_system: Option<String>,
}
Expand All @@ -357,33 +367,43 @@ pub struct HardwareInfo {
#[serde(rename = "name")]
pub name: String,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "version")]
pub version: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "revision")]
pub revision: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "location")]
pub location: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "serialNumber")]
pub serial_no: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "partNumber")]
pub part_no: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "manufacturer")]
pub manufacturer: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "manufacturerPartNumber")]
pub manufacturer_part_no: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "odataId")]
pub odata_id: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "computerSystem")]
pub computer_system: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "manager")]
pub manager: Option<String>,
}
Expand Down Expand Up @@ -415,13 +435,16 @@ pub struct Error {
#[serde(rename = "symptom")]
pub symptom: String,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "message")]
pub message: Option<String>,

// TODO: support this field during serialization to print only the id of SoftwareInfo struct
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "softwareInfoIds")]
pub software_infos: Option<Vec<SoftwareInfo>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "sourceLocation")]
pub source_location: Option<SourceLocation>,
}
Expand All @@ -440,6 +463,7 @@ pub struct Log {
#[serde(rename = "message")]
pub message: String,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "sourceLocation")]
pub source_location: Option<SourceLocation>,
}
Expand Down Expand Up @@ -548,18 +572,23 @@ pub struct Measurement {
#[serde(rename = "value")]
pub value: Value,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "unit")]
pub unit: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "validators")]
pub validators: Option<Vec<Validator>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "hardwareInfoId")]
pub hardware_info_id: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "subcomponent")]
pub subcomponent: Option<Subcomponent>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "metadata")]
pub metadata: Option<Map<String, Value>>,
}
Expand All @@ -572,6 +601,7 @@ pub struct Measurement {
#[derive(Debug, Serialize, Clone, PartialEq)]
#[serde(rename = "validator")]
pub struct Validator {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "name")]
pub name: Option<String>,

Expand All @@ -581,6 +611,7 @@ pub struct Validator {
#[serde(rename = "value")]
pub value: Value,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "metadata")]
pub metadata: Option<Map<String, Value>>,
}
Expand All @@ -593,18 +624,22 @@ pub struct Validator {
#[derive(Debug, Serialize, Clone, PartialEq)]
#[serde(rename = "subcomponent")]
pub struct Subcomponent {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "type")]
pub subcomponent_type: Option<SubcomponentType>,

#[serde(rename = "name")]
pub name: String,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "location")]
pub location: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "version")]
pub version: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "revision")]
pub revision: Option<String>,
}
Expand All @@ -620,21 +655,26 @@ pub struct MeasurementSeriesStart {
#[serde(rename = "name")]
pub name: String,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "unit")]
pub unit: Option<String>,

#[serde(rename = "measurementSeriesId")]
pub series_id: String,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "validators")]
pub validators: Option<Vec<Validator>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "hardwareInfoId")]
pub hardware_info: Option<HardwareInfo>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "subcomponent")]
pub subcomponent: Option<Subcomponent>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "metadata")]
pub metadata: Option<Map<String, Value>>,
}
Expand Down Expand Up @@ -674,6 +714,7 @@ pub struct MeasurementSeriesElement {
#[serde(rename = "measurementSeriesId")]
pub series_id: String,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "metadata")]
pub metadata: Option<Map<String, Value>>,
}
Expand All @@ -692,15 +733,19 @@ pub struct Diagnosis {
#[serde(rename = "type")]
pub diagnosis_type: DiagnosisType,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "message")]
pub message: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "validators")]
pub hardware_info: Option<HardwareInfo>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "subComponent")]
pub subcomponent: Option<Subcomponent>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "sourceLocation")]
pub source_location: Option<SourceLocation>,
}
Expand All @@ -722,12 +767,15 @@ pub struct File {
#[serde(rename = "isSnapshot")]
pub is_snapshot: bool,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "description")]
pub description: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "contentType")]
pub content_type: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "metadata")]
pub metadata: Option<Map<String, Value>>,
}
Expand Down
Loading

0 comments on commit b5f9fe2

Please sign in to comment.