use std::collections::HashMap;
#[cfg(feature = "yaml")] use anyhow::anyhow;
use itertools::Either;
use serde_json::Value;
#[cfg(feature = "yaml")] use yaml_rust2::Yaml;
#[cfg(feature = "yaml")] use yaml_rust2::yaml::Hash;
use crate::extensions::ExtensionValue;
#[cfg(feature = "yaml")] use crate::extensions::yaml_extract_extensions;
#[cfg(feature = "yaml")] use crate::yaml::{
yaml_hash_entry_to_json,
yaml_hash_lookup,
yaml_hash_lookup_integer,
yaml_hash_lookup_number,
yaml_hash_lookup_string,
yaml_hash_lookup_string_list,
yaml_hash_require_string,
yaml_type_name
};
#[derive(Debug, Clone)]
pub struct ArazzoDescription {
pub arazzo: String,
pub info: Info,
pub source_descriptions: Vec<SourceDescription>,
pub workflows: Vec<Workflow>,
pub components: Components,
pub extensions: HashMap<String, ExtensionValue>,
}
#[cfg(feature = "yaml")]
impl TryFrom<&Yaml> for ArazzoDescription {
type Error = anyhow::Error;
fn try_from(value: &Yaml) -> Result<Self, Self::Error> {
if let Some(hash) = value.as_hash() {
if let Ok(version) = yaml_hash_require_string(hash, "arazzo") {
let info = Info::try_from(hash)?;
let source_descriptions = yaml_load_source_descriptions(hash)?;
let workflows = yaml_load_workflows(hash)?;
let components = Components::try_from(hash)?;
Ok(ArazzoDescription {
arazzo: version,
info,
source_descriptions,
workflows,
components,
extensions: yaml_extract_extensions(&hash)?
})
} else {
Err(anyhow!("Arazzo version number is required [4.6.1.1 Fixed Fields]"))
}
} else {
Err(anyhow!("YAML value must be a Hash, got {}", yaml_type_name(value)))
}
}
}
#[derive(Debug, Clone)]
pub struct Info {
pub title: String,
pub summary: Option<String>,
pub description: Option<String>,
pub version: String,
pub extensions: HashMap<String, ExtensionValue>
}
#[cfg(feature = "yaml")]
impl TryFrom<&Hash> for Info {
type Error = anyhow::Error;
fn try_from(value: &Hash) -> Result<Self, Self::Error> {
if let Some(hash) = yaml_hash_lookup(value, "info", |v | v.as_hash().cloned()) {
Ok(Info {
title: yaml_hash_require_string(&hash, "title")?,
summary: yaml_hash_lookup_string(&hash, "summary"),
description: yaml_hash_lookup_string(&hash, "description"),
version: yaml_hash_require_string(&hash, "version")?,
extensions: yaml_extract_extensions(&hash)?
})
} else {
Err(anyhow!("Info Object is required [4.6.1.1 Fixed Fields]"))
}
}
}
#[derive(Debug, Clone)]
pub struct SourceDescription {
pub name: String,
pub url: String,
pub r#type: Option<String>,
pub extensions: HashMap<String, ExtensionValue>
}
#[cfg(feature = "yaml")]
fn yaml_load_source_descriptions(hash: &Hash) -> anyhow::Result<Vec<SourceDescription>> {
if let Some(array) = yaml_hash_lookup(hash, "sourceDescriptions", |v | v.as_vec().cloned()) {
if array.is_empty() {
Err(anyhow!("Source Description list must have at least one entry [4.6.1.1 Fixed Fields]"))
} else {
let mut list = vec![];
for item in &array {
list.push(SourceDescription::try_from(item)?);
}
Ok(list)
}
} else {
Err(anyhow!("Source Description Object is required [4.6.1.1 Fixed Fields]"))
}
}
#[cfg(feature = "yaml")]
impl TryFrom<&Yaml> for SourceDescription {
type Error = anyhow::Error;
fn try_from(value: &Yaml) -> Result<Self, Self::Error> {
if let Some(hash) = value.as_hash() {
Ok(SourceDescription {
name: yaml_hash_require_string(&hash, "name")?,
url: yaml_hash_require_string(&hash, "url")?,
r#type: yaml_hash_lookup_string(&hash, "type"),
extensions: yaml_extract_extensions(&hash)?
})
} else {
Err(anyhow!("YAML value must be a Hash, got {}", yaml_type_name(value)))
}
}
}
#[derive(Debug, Clone)]
pub struct Workflow {
pub workflow_id: String,
pub summary: Option<String>,
pub description: Option<String>,
pub inputs: Value,
pub depends_on: Vec<String>,
pub steps: Vec<Step>,
pub success_actions: Vec<Either<SuccessObject, ReusableObject>>,
pub failure_actions: Vec<Either<FailureObject, ReusableObject>>,
pub extensions: HashMap<String, ExtensionValue>
}
#[cfg(feature = "yaml")]
fn yaml_load_workflows(hash: &Hash) -> anyhow::Result<Vec<Workflow>> {
if let Some(array) = yaml_hash_lookup(hash, "workflows", |v | v.as_vec().cloned()) {
if array.is_empty() {
Err(anyhow!("Workflows list must have at least one entry [4.6.1.1 Fixed Fields]"))
} else {
let mut list = vec![];
for item in &array {
list.push(Workflow::try_from(item)?);
}
Ok(list)
}
} else {
Err(anyhow!("Workflow Object is required [4.6.1.1 Fixed Fields]"))
}
}
#[cfg(feature = "yaml")]
impl TryFrom<&Yaml> for Workflow {
type Error = anyhow::Error;
fn try_from(value: &Yaml) -> Result<Self, Self::Error> {
if let Some(hash) = value.as_hash() {
Ok(Workflow {
workflow_id: yaml_hash_require_string(&hash, "workflowId")?,
summary: yaml_hash_lookup_string(&hash, "summary"),
description: yaml_hash_lookup_string(&hash, "description"),
inputs: yaml_hash_entry_to_json(&hash, "inputs")?,
depends_on: yaml_hash_lookup_string_list(&hash, "dependsOn").unwrap_or_default(),
steps: yaml_load_steps(hash)?,
success_actions: yaml_load_success_actions(hash)?,
failure_actions: yaml_load_failure_actions(hash)?,
extensions: yaml_extract_extensions(&hash)?
})
} else {
Err(anyhow!("YAML value must be a Hash, got {}", yaml_type_name(value)))
}
}
}
#[derive(Debug, Clone)]
pub struct Step {
pub extensions: HashMap<String, ExtensionValue>
}
#[cfg(feature = "yaml")]
fn yaml_load_steps(hash: &Hash) -> anyhow::Result<Vec<Step>> {
if let Some(array) = yaml_hash_lookup(hash, "steps", |v | v.as_vec().cloned()) {
if array.is_empty() {
Err(anyhow!("At lest one Step is required [4.6.4.1 Fixed Fields]"))
} else {
let mut list = vec![];
for item in &array {
list.push(Step::try_from(item)?);
}
Ok(list)
}
} else {
Err(anyhow!("At lest one Step is required [4.6.4.1 Fixed Fields]"))
}
}
#[cfg(feature = "yaml")]
impl TryFrom<&Yaml> for Step {
type Error = anyhow::Error;
fn try_from(value: &Yaml) -> Result<Self, Self::Error> {
if let Some(hash) = value.as_hash() {
Ok(Step {
extensions: yaml_extract_extensions(&hash)?
})
} else {
Err(anyhow!("YAML value must be a Hash, got {}", yaml_type_name(value)))
}
}
}
#[cfg(feature = "yaml")]
fn yaml_load_success_actions(hash: &Hash) -> anyhow::Result<Vec<Either<SuccessObject, ReusableObject>>> {
if let Some(array) = yaml_hash_lookup(hash, "successActions", |v | v.as_vec().cloned()) {
let mut list = vec![];
for item in &array {
if let Some(hash) = item.as_hash() {
if hash.contains_key(&Yaml::String("reference".to_string())) {
list.push(Either::Right(ReusableObject::try_from(hash)?));
} else {
list.push(Either::Left(SuccessObject::try_from(hash)?));
}
}
}
Ok(list)
} else {
Ok(vec![])
}
}
#[cfg(feature = "yaml")]
fn yaml_load_failure_actions(hash: &Hash) -> anyhow::Result<Vec<Either<FailureObject, ReusableObject>>> {
if let Some(array) = yaml_hash_lookup(hash, "failureActions", |v | v.as_vec().cloned()) {
let mut list = vec![];
for item in &array {
if let Some(hash) = item.as_hash() {
if hash.contains_key(&Yaml::String("reference".to_string())) {
list.push(Either::Right(ReusableObject::try_from(hash)?));
} else {
list.push(Either::Left(FailureObject::try_from(hash)?));
}
}
}
Ok(list)
} else {
Ok(vec![])
}
}
#[derive(Debug, Clone)]
pub struct SuccessObject {
pub name: String,
pub r#type: String,
pub workflow_id: Option<String>,
pub step_id: Option<String>,
pub extensions: HashMap<String, ExtensionValue>
}
#[cfg(feature = "yaml")]
impl TryFrom<&Hash> for SuccessObject {
type Error = anyhow::Error;
fn try_from(value: &Hash) -> Result<Self, Self::Error> {
Ok(SuccessObject {
name: yaml_hash_require_string(value, "name")?,
r#type: yaml_hash_require_string(value, "type")?,
workflow_id: yaml_hash_lookup_string(value, "workflowId"),
step_id: yaml_hash_lookup_string(value, "stepId"),
extensions: yaml_extract_extensions(value)?
})
}
}
#[derive(Debug, Clone)]
pub struct FailureObject {
pub name: String,
pub r#type: String,
pub workflow_id: Option<String>,
pub step_id: Option<String>,
pub retry_after: Option<f64>,
pub retry_limit: Option<i64>,
pub extensions: HashMap<String, ExtensionValue>
}
#[cfg(feature = "yaml")]
impl TryFrom<&Hash> for FailureObject {
type Error = anyhow::Error;
fn try_from(value: &Hash) -> Result<Self, Self::Error> {
Ok(FailureObject {
name: yaml_hash_require_string(value, "name")?,
r#type: yaml_hash_require_string(value, "type")?,
workflow_id: yaml_hash_lookup_string(value, "workflowId"),
step_id: yaml_hash_lookup_string(value, "stepId"),
retry_after: yaml_hash_lookup_number(value, "retryAfter"),
retry_limit: yaml_hash_lookup_integer(value, "retryLimit"),
extensions: yaml_extract_extensions(value)?
})
}
}
#[derive(Debug, Clone, Default)]
pub struct Components {
pub extensions: HashMap<String, ExtensionValue>
}
#[cfg(feature = "yaml")]
impl TryFrom<&Hash> for Components {
type Error = anyhow::Error;
fn try_from(value: &Hash) -> Result<Self, Self::Error> {
if let Some(hash) = yaml_hash_lookup(value, "components", |v | v.as_hash().cloned()) {
Ok(Components {
extensions: yaml_extract_extensions(&hash)?
})
} else {
Ok(Components::default())
}
}
}
#[derive(Debug, Clone)]
pub struct ReusableObject {
pub reference: String,
pub value: Option<String>
}
#[cfg(feature = "yaml")]
impl TryFrom<&Hash> for ReusableObject {
type Error = anyhow::Error;
fn try_from(value: &Hash) -> Result<Self, Self::Error> {
if let Ok(reference) = yaml_hash_require_string(value, "reference") {
Ok(ReusableObject {
reference,
value: yaml_hash_lookup_string(value, "value")
})
} else {
Err(anyhow!("Reference is required [4.6.10.1 Fixed Fields]"))
}
}
}
#[cfg(test)]
#[cfg(feature = "yaml")]
mod yaml_tests {
use expectest::prelude::*;
use maplit::hashmap;
use yaml_rust2::Yaml;
use yaml_rust2::yaml::Hash;
use crate::extensions::ExtensionValue;
use crate::v1_0::*;
#[test]
fn fails_to_load_if_the_main_value_is_not_a_yaml_hash() {
expect!(ArazzoDescription::try_from(&Yaml::String("test".to_string()))).to(be_err());
}
#[test]
fn fails_to_load_if_the_version_is_missing() {
expect!(ArazzoDescription::try_from(&Yaml::Hash(Hash::new()))).to(be_err());
}
#[test]
fn fails_to_load_if_the_version_is_not_a_string() {
let mut hash = Hash::new();
hash.insert(Yaml::String("arazzo".to_string()), Yaml::Hash(Hash::new()));
expect!(ArazzoDescription::try_from(&Yaml::Hash(hash))).to(be_err());
}
#[test]
fn fails_to_load_if_the_info_is_missing() {
let mut hash = Hash::new();
hash.insert(Yaml::String("arazzo".to_string()), Yaml::String("1.0.0".to_string()));
expect!(ArazzoDescription::try_from(&Yaml::Hash(hash))).to(be_err());
}
#[test]
fn fails_to_load_if_the_source_descriptions_are_missing() {
let mut hash = Hash::new();
hash.insert(Yaml::String("arazzo".to_string()), Yaml::String("1.0.0".to_string()));
hash.insert(Yaml::String("info".to_string()), Yaml::Hash(info_fixture()));
expect!(ArazzoDescription::try_from(&Yaml::Hash(hash))).to(be_err());
}
#[test]
fn fails_to_load_if_the_source_descriptions_are_empty() {
let mut hash = Hash::new();
hash.insert(Yaml::String("arazzo".to_string()), Yaml::String("1.0.0".to_string()));
hash.insert(Yaml::String("info".to_string()), Yaml::Hash(info_fixture()));
hash.insert(Yaml::String("sourceDescriptions".to_string()), Yaml::Array(vec![]));
expect!(ArazzoDescription::try_from(&Yaml::Hash(hash))).to(be_err());
}
#[test]
fn fails_to_load_if_the_workflows_are_missing() {
let mut hash = Hash::new();
hash.insert(Yaml::String("arazzo".to_string()), Yaml::String("1.0.0".to_string()));
hash.insert(Yaml::String("info".to_string()), Yaml::Hash(info_fixture()));
hash.insert(Yaml::String("sourceDescriptions".to_string()), Yaml::Array(source_descriptions_fixture()));
expect!(ArazzoDescription::try_from(&Yaml::Hash(hash))).to(be_err());
}
#[test]
fn fails_to_load_if_the_workflows_are_empty() {
let mut hash = Hash::new();
hash.insert(Yaml::String("arazzo".to_string()), Yaml::String("1.0.0".to_string()));
hash.insert(Yaml::String("info".to_string()), Yaml::Hash(info_fixture()));
hash.insert(Yaml::String("sourceDescriptions".to_string()), Yaml::Array(source_descriptions_fixture()));
hash.insert(Yaml::String("workflows".to_string()), Yaml::Array(vec![]));
expect!(ArazzoDescription::try_from(&Yaml::Hash(hash))).to(be_err());
}
#[test]
fn arazzo_description_supports_extensions() {
let mut hash = Hash::new();
hash.insert(Yaml::String("arazzo".to_string()), Yaml::String("1.0.0".to_string()));
hash.insert(Yaml::String("x-one".to_string()), Yaml::String("1".to_string()));
hash.insert(Yaml::String("x-two".to_string()), Yaml::Integer(2));
hash.insert(Yaml::String("info".to_string()), Yaml::Hash(info_fixture()));
hash.insert(Yaml::String("sourceDescriptions".to_string()), Yaml::Array(source_descriptions_fixture()));
hash.insert(Yaml::String("workflows".to_string()), Yaml::Array(workflows_fixture()));
let desc = ArazzoDescription::try_from(&Yaml::Hash(hash)).unwrap();
expect!(desc.extensions).to(be_equal_to(hashmap!{
"one".to_string() => ExtensionValue::String("1".to_string()),
"two".to_string() => ExtensionValue::Integer(2)
}));
}
fn info_fixture() -> Hash {
let mut info = Hash::new();
info.insert(Yaml::String("title".to_string()), Yaml::String("test".to_string()));
info.insert(Yaml::String("version".to_string()), Yaml::String("1.0.0".to_string()));
info
}
fn source_descriptions_fixture() -> Vec<Yaml> {
let mut desc = Hash::new();
desc.insert(Yaml::String("name".to_string()), Yaml::String("test".to_string()));
desc.insert(Yaml::String("url".to_string()), Yaml::String("http://test".to_string()));
vec![Yaml::Hash(desc)]
}
fn workflows_fixture() -> Vec<Yaml> {
let mut wf = Hash::new();
wf.insert(Yaml::String("workflowId".to_string()), Yaml::String("test".to_string()));
wf.insert(Yaml::String("steps".to_string()), Yaml::Array(steps_fixture()));
vec![Yaml::Hash(wf)]
}
fn steps_fixture() -> Vec<Yaml> {
let mut desc = Hash::new();
desc.insert(Yaml::String("stepId".to_string()), Yaml::String("test".to_string()));
vec![Yaml::Hash(desc)]
}
#[test]
fn info_supports_extensions() {
let mut hash = Hash::new();
hash.insert(Yaml::String("title".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("version".to_string()), Yaml::String("1.0.0".to_string()));
hash.insert(Yaml::String("x-one".to_string()), Yaml::String("1".to_string()));
hash.insert(Yaml::String("x-two".to_string()), Yaml::Integer(2));
let mut outer = Hash::new();
outer.insert(Yaml::String("info".to_string()), Yaml::Hash(hash));
let info = Info::try_from(&outer).unwrap();
expect!(info.extensions).to(be_equal_to(hashmap!{
"one".to_string() => ExtensionValue::String("1".to_string()),
"two".to_string() => ExtensionValue::Integer(2)
}));
}
#[test]
fn source_description_supports_extensions() {
let mut hash = Hash::new();
hash.insert(Yaml::String("name".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("url".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("x-one".to_string()), Yaml::String("1".to_string()));
hash.insert(Yaml::String("x-two".to_string()), Yaml::Integer(2));
let desc = SourceDescription::try_from(&Yaml::Hash(hash)).unwrap();
expect!(desc.extensions).to(be_equal_to(hashmap!{
"one".to_string() => ExtensionValue::String("1".to_string()),
"two".to_string() => ExtensionValue::Integer(2)
}));
}
#[test]
fn workflow_fails_to_load_if_there_are_no_steps() {
let mut hash = Hash::new();
hash.insert(Yaml::String("workflowId".to_string()), Yaml::String("test".to_string()));
expect!(Workflow::try_from(&Yaml::Hash(hash.clone()))).to(be_err());
hash.insert(Yaml::String("steps".to_string()), Yaml::Array(vec![]));
expect!(Workflow::try_from(&Yaml::Hash(hash))).to(be_err());
}
#[test]
fn workflow_supports_extensions() {
let mut hash = Hash::new();
hash.insert(Yaml::String("workflowId".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("steps".to_string()), Yaml::Array(steps_fixture()));
hash.insert(Yaml::String("x-one".to_string()), Yaml::String("1".to_string()));
hash.insert(Yaml::String("x-two".to_string()), Yaml::Integer(2));
let wf = Workflow::try_from(&Yaml::Hash(hash)).unwrap();
expect!(wf.extensions).to(be_equal_to(hashmap!{
"one".to_string() => ExtensionValue::String("1".to_string()),
"two".to_string() => ExtensionValue::Integer(2)
}));
}
#[test]
fn steps_supports_extensions() {
let mut hash = Hash::new();
hash.insert(Yaml::String("stepId".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("x-one".to_string()), Yaml::String("1".to_string()));
hash.insert(Yaml::String("x-two".to_string()), Yaml::Integer(2));
let step = Step::try_from(&Yaml::Hash(hash)).unwrap();
expect!(step.extensions).to(be_equal_to(hashmap!{
"one".to_string() => ExtensionValue::String("1".to_string()),
"two".to_string() => ExtensionValue::Integer(2)
}));
}
#[test]
fn components_supports_extensions() {
let mut hash = Hash::new();
hash.insert(Yaml::String("workflowId".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("x-one".to_string()), Yaml::String("1".to_string()));
hash.insert(Yaml::String("x-two".to_string()), Yaml::Integer(2));
let mut outer = Hash::new();
outer.insert(Yaml::String("components".to_string()), Yaml::Hash(hash));
let components = Components::try_from(&outer).unwrap();
expect!(components.extensions).to(be_equal_to(hashmap!{
"one".to_string() => ExtensionValue::String("1".to_string()),
"two".to_string() => ExtensionValue::Integer(2)
}));
}
#[test]
fn load_success_object() {
let mut hash = Hash::new();
hash.insert(Yaml::String("name".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("type".to_string()), Yaml::String("end".to_string()));
hash.insert(Yaml::String("workflowId".to_string()), Yaml::String("workflowId".to_string()));
hash.insert(Yaml::String("stepId".to_string()), Yaml::String("stepId".to_string()));
let success = SuccessObject::try_from(&hash).unwrap();
expect!(&success.name).to(be_equal_to("test"));
expect!(&success.r#type).to(be_equal_to("end"));
expect!(success.workflow_id.clone()).to(be_some().value("workflowId"));
expect!(success.step_id.clone()).to(be_some().value("stepId"));
let mut hash = Hash::new();
hash.insert(Yaml::String("name".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("type".to_string()), Yaml::String("end".to_string()));
let success = SuccessObject::try_from(&hash).unwrap();
expect!(&success.name).to(be_equal_to("test"));
expect!(&success.r#type).to(be_equal_to("end"));
expect!(success.workflow_id.clone()).to(be_none());
expect!(success.step_id.clone()).to(be_none());
}
#[test]
fn success_object_supports_extensions() {
let mut hash = Hash::new();
hash.insert(Yaml::String("name".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("type".to_string()), Yaml::String("end".to_string()));
hash.insert(Yaml::String("x-one".to_string()), Yaml::String("1".to_string()));
hash.insert(Yaml::String("x-two".to_string()), Yaml::Integer(2));
let success = SuccessObject::try_from(&hash).unwrap();
expect!(success.extensions).to(be_equal_to(hashmap!{
"one".to_string() => ExtensionValue::String("1".to_string()),
"two".to_string() => ExtensionValue::Integer(2)
}));
}
#[test]
fn load_failure_object() {
let mut hash = Hash::new();
hash.insert(Yaml::String("name".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("type".to_string()), Yaml::String("end".to_string()));
hash.insert(Yaml::String("workflowId".to_string()), Yaml::String("workflowId".to_string()));
hash.insert(Yaml::String("stepId".to_string()), Yaml::String("stepId".to_string()));
hash.insert(Yaml::String("retryAfter".to_string()), Yaml::Real("10.5".to_string()));
hash.insert(Yaml::String("retryLimit".to_string()), Yaml::Integer(10));
let failure = FailureObject::try_from(&hash).unwrap();
expect!(&failure.name).to(be_equal_to("test"));
expect!(&failure.r#type).to(be_equal_to("end"));
expect!(failure.workflow_id.clone()).to(be_some().value("workflowId"));
expect!(failure.step_id.clone()).to(be_some().value("stepId"));
expect!(failure.retry_after.clone()).to(be_some().value(10.5));
expect!(failure.retry_limit.clone()).to(be_some().value(10));
let mut hash = Hash::new();
hash.insert(Yaml::String("name".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("type".to_string()), Yaml::String("end".to_string()));
let failure = FailureObject::try_from(&hash).unwrap();
expect!(&failure.name).to(be_equal_to("test"));
expect!(&failure.r#type).to(be_equal_to("end"));
expect!(failure.workflow_id.clone()).to(be_none());
expect!(failure.step_id.clone()).to(be_none());
expect!(failure.retry_after.clone()).to(be_none());
expect!(failure.retry_limit.clone()).to(be_none());
}
#[test]
fn failure_object_supports_extensions() {
let mut hash = Hash::new();
hash.insert(Yaml::String("name".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("type".to_string()), Yaml::String("end".to_string()));
hash.insert(Yaml::String("x-one".to_string()), Yaml::String("1".to_string()));
hash.insert(Yaml::String("x-two".to_string()), Yaml::Integer(2));
let failure = FailureObject::try_from(&hash).unwrap();
expect!(failure.extensions).to(be_equal_to(hashmap!{
"one".to_string() => ExtensionValue::String("1".to_string()),
"two".to_string() => ExtensionValue::Integer(2)
}));
}
#[test]
fn load_reusable_object() {
let mut hash = Hash::new();
hash.insert(Yaml::String("reference".to_string()), Yaml::String("$test".to_string()));
hash.insert(Yaml::String("value".to_string()), Yaml::String("test".to_string()));
hash.insert(Yaml::String("workflowId".to_string()), Yaml::String("workflowId".to_string()));
let obj = ReusableObject::try_from(&hash).unwrap();
expect!(&obj.reference).to(be_equal_to("$test"));
expect!(obj.value.clone()).to(be_some().value("test"));
let mut hash = Hash::new();
hash.insert(Yaml::String("reference".to_string()), Yaml::String("$test".to_string()));
let obj = ReusableObject::try_from(&hash).unwrap();
expect!(&obj.reference).to(be_equal_to("$test"));
expect!(obj.value.clone()).to(be_none());
}
}