Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,74 @@ mod unit_tests {
assert!(script.environment.is_some());
assert_eq!(script.environment.as_ref().unwrap().get("FOO"), Some(&"bar".to_string()));
}

#[test]
fn test_extension_definition_serialization() {
let extension_json = json!({
"document": {
"dsl": "1.0.2",
"namespace": "test",
"name": "sample-workflow",
"version": "0.1.0"
},
"use": {
"extensions": [
{
"mockService": {
"extend": "call",
"when": "($task.with.endpoint != null and ($task.with.endpoint | startswith(\"https://mocked.service.com\"))) or ($task.with.endpoint.uri != null and ($task.with.endpoint.uri | startswith(\"https://mocked.service.com\")))",
"before": [
{
"mockResponse": {
"set": {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"content": {
"foo": {
"bar": "baz"
}
}
},
"then": "exit"
}
}
]
}
}
]
},
"do": [
{
"callHttp": {
"call": "http",
"with": {
"method": "get",
"endpoint": {
"uri": "https://fake.com/sample"
}
}
}
}
]
});
let result: Result<WorkflowDefinition, _> = serde_json::from_value(extension_json);
match result {
Ok(workflow) => {
// Verify the workflow was deserialized correctly
assert_eq!(workflow.document.namespace, "test");
assert_eq!(workflow.document.name, "sample-workflow");
assert_eq!(workflow.document.version, "0.1.0");
// Verify the use section exists with extensions
assert!(workflow.use_.is_some());
if let Some(use_def) = workflow.use_ {
assert!(use_def.extensions.is_some());
}
}
Err(e) => {
panic!("Failed to deserialize workflow with extension: {}", e);
}
}
}
}
9 changes: 4 additions & 5 deletions core/src/models/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ pub struct ExtensionDefinition{
#[serde(rename = "when", skip_serializing_if = "Option::is_none")]
pub when: Option<String>,

/// Gets/sets a name/definition map, if any, of the tasks to execute before the extended task
/// Gets/sets a name/definition list, if any, of the tasks to execute before the extended task
#[serde(rename = "before", skip_serializing_if = "Option::is_none")]
pub before: Option<HashMap<String, TaskDefinition>>,
pub before: Option<Vec<HashMap<String, TaskDefinition>>>,

/// Gets/sets a name/definition map, if any, of the tasks to execute after the extended task
/// Gets/sets a name/definition list, if any, of the tasks to execute after the extended task
#[serde(rename = "after", skip_serializing_if = "Option::is_none")]
pub after: Option<HashMap<String, TaskDefinition>>

pub after: Option<Vec<HashMap<String, TaskDefinition>>>
}
13 changes: 11 additions & 2 deletions core/src/models/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,16 +715,25 @@ pub struct ContainerProcessDefinition{
#[serde(rename = "environment", skip_serializing_if = "Option::is_none")]
pub environment: Option<HashMap<String, String>>,

/// Gets/sets the data to pass to the process via stdin, if any
#[serde(rename = "stdin", skip_serializing_if = "Option::is_none")]
pub stdin: Option<String>,

/// Gets/sets a list of arguments, if any, to pass to the container (argv)
#[serde(rename = "arguments", skip_serializing_if = "Option::is_none")]
pub arguments: Option<Vec<String>>,
}
impl ContainerProcessDefinition {
pub fn new(image: &str, name: Option<String>, command: Option<String>, ports: Option<HashMap<u16, u16>>, volumes: Option<HashMap<String, String>>, environment: Option<HashMap<String, String>>) -> Self{
pub fn new(image: &str, name: Option<String>, command: Option<String>, ports: Option<HashMap<u16, u16>>, volumes: Option<HashMap<String, String>>, environment: Option<HashMap<String, String>>, stdin: Option<String>, arguments: Option<Vec<String>>) -> Self{
Self {
image: image.to_string(),
name,
command,
ports,
volumes,
environment
environment,
stdin,
arguments,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/models/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ pub struct ComponentDefinitionCollection{
#[serde(rename = "errors", skip_serializing_if = "Option::is_none")]
pub errors: Option<HashMap<String, ErrorDefinition>>,

/// Gets/sets a name/value mapping of the workflow's extensions, if any
/// Gets/sets a list containing the workflow's extensions, if any
#[serde(rename = "extensions", skip_serializing_if = "Option::is_none")]
pub extensions: Option<HashMap<String, ExtensionDefinition>>,
pub extensions: Option<Vec<HashMap<String, ExtensionDefinition>>>,

/// Gets/sets a name/value mapping of the workflow's reusable functions
#[serde(rename = "functions", skip_serializing_if = "Option::is_none")]
Expand Down
Loading