Skip to content

Commit

Permalink
integer param type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erratic-pattern committed Jul 18, 2023
1 parent c229b00 commit 12d10e7
Show file tree
Hide file tree
Showing 3 changed files with 417 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/harness/src/output.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod audit_log;
pub mod param_types;
pub mod parameter;
pub mod profile;
pub mod template;
70 changes: 70 additions & 0 deletions tests/harness/src/output/param_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use std::ops::{Deref, DerefMut};

use serde::Deserialize;

#[derive(Clone, Debug, Deserialize)]
pub struct ParamTypesListRoot<T> {
#[serde(rename = "parameter-type")]
parameter_type: ParamTypesList<T>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct ParamTypesList<T>(Vec<T>);

impl<T> Deref for ParamTypesList<T> {
type Target = Vec<T>;
fn deref(&self) -> &Self::Target {
&self.0
}
}

impl<T> DerefMut for ParamTypesList<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ParamTypeEntry {
pub description: String,
pub name: String,
pub parent: String,
pub rules: String,
#[serde(rename = "Created At")]
pub created_at: Option<String>,
#[serde(rename = "Modified At")]
pub modified_at: Option<String>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ConstraintEntry {
pub constraint: String,
pub name: String,
pub parent: String,
#[serde(rename = "Rule Type")]
pub rule_type: String,
#[serde(rename = "Created At")]
pub created_at: Option<String>,
#[serde(rename = "Modified At")]
pub modified_at: Option<String>,
}

pub trait ParseParamTypesExt {
fn parse_param_types_list(&self) -> ParamTypesList<ParamTypeEntry>;
fn parse_param_types_list_with_rules(&self) -> ParamTypesList<ConstraintEntry>;
}

impl ParseParamTypesExt for assert_cmd::assert::Assert {
fn parse_param_types_list(&self) -> ParamTypesList<ParamTypeEntry> {
serde_json::from_slice::<ParamTypesListRoot<ParamTypeEntry>>(&self.get_output().stdout)
.expect("Unable to parse JSON as param types list")
.parameter_type
}
fn parse_param_types_list_with_rules(&self) -> ParamTypesList<ConstraintEntry> {
serde_json::from_slice::<ParamTypesListRoot<ConstraintEntry>>(&self.get_output().stdout)
.expect("Unable to parse JSON as param types list")
.parameter_type
}
}
Loading

0 comments on commit 12d10e7

Please sign in to comment.