Skip to content

Commit

Permalink
Populate example data to utests
Browse files Browse the repository at this point in the history
  • Loading branch information
inf17101 committed Dec 18, 2024
1 parent 9e89c80 commit afee47c
Show file tree
Hide file tree
Showing 10 changed files with 279 additions and 21 deletions.
8 changes: 6 additions & 2 deletions agent/src/runtime_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,8 @@ mod tests {
runtime_config: Some("generalOptions: [\"--version\"]\ncommandOptions: [\"--network=host\"]\nimage: alpine:latest\ncommandArgs: [\"bash\"]\n".to_string()),
control_interface_access: None,
configs: Some(ank_base::ConfigMappings {
configs: Default::default()})
configs: Default::default()}),
files: None,
})];
let mut complete_state = test_utils::generate_test_proto_complete_state(&workloads);
complete_state.workload_states = Some(ank_base::WorkloadStatesMap {
Expand Down Expand Up @@ -2117,7 +2118,10 @@ mod tests {
mock_workload
.expect_forward_response()
.once()
.with(predicate::eq(expected_response))
.with(predicate::function(move |arg| {
assert_eq!(arg, &expected_response);
false
}))
.return_once(move |_| {
Err(WorkloadError::CompleteState(
"failed to send complete state".to_string(),
Expand Down
134 changes: 131 additions & 3 deletions ank/src/cli_commands/server_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,22 @@ mod tests {
]
.into(),
}),
files: Some(ank_base::Files {
files: vec![
ank_base::File {
mount_point: "/file.json".into(),
file_content: Some(ank_base::file::FileContent::Data(
"text data".into(),
)),
},
ank_base::File {
mount_point: "/binary_file".into(),
file_content: Some(ank_base::file::FileContent::BinaryData(
"base64_data".into(),
)),
},
],
}),
},
)]),
),
Expand Down Expand Up @@ -463,7 +479,23 @@ mod tests {
("ref2".into(), "config_2".into()),
]
.into()
})
}),
files: Some(ank_base::Files {
files: vec![
ank_base::File {
mount_point: "/file.json".into(),
file_content: Some(ank_base::file::FileContent::Data(
"text data".into()
)),
},
ank_base::File {
mount_point: "/binary_file".into(),
file_content: Some(ank_base::file::FileContent::BinaryData(
"base64_data".into()
)),
}
],
}),
},
)])
.into())
Expand Down Expand Up @@ -547,6 +579,22 @@ mod tests {
]
.into(),
}),
files: Some(ank_base::Files {
files: vec![
ank_base::File {
mount_point: "/file.json".into(),
file_content: Some(ank_base::file::FileContent::Data(
"text data".into(),
)),
},
ank_base::File {
mount_point: "/binary_file".into(),
file_content: Some(ank_base::file::FileContent::BinaryData(
"base64_data".into(),
)),
},
],
}),
},
)]),
)),
Expand Down Expand Up @@ -582,6 +630,22 @@ mod tests {
]
.into(),
}),
files: Some(ank_base::Files {
files: vec![
ank_base::File {
mount_point: "/file.json".into(),
file_content: Some(ank_base::file::FileContent::Data(
"text data".into(),
)),
},
ank_base::File {
mount_point: "/binary_file".into(),
file_content: Some(ank_base::file::FileContent::BinaryData(
"base64_data".into(),
)),
},
],
}),
},
)]),
),
Expand Down Expand Up @@ -612,7 +676,23 @@ mod tests {
("ref2".into(), "config_2".into()),
]
.into()
})
}),
files: Some(ank_base::Files {
files: vec![
ank_base::File {
mount_point: "/file.json".into(),
file_content: Some(ank_base::file::FileContent::Data(
"text data".into()
)),
},
ank_base::File {
mount_point: "/binary_file".into(),
file_content: Some(ank_base::file::FileContent::BinaryData(
"base64_data".into()
)),
}
],
}),
},
)])
.into())
Expand Down Expand Up @@ -661,6 +741,22 @@ mod tests {
]
.into(),
}),
files: Some(ank_base::Files {
files: vec![
ank_base::File {
mount_point: "/file.json".into(),
file_content: Some(ank_base::file::FileContent::Data(
"text data".into(),
)),
},
ank_base::File {
mount_point: "/binary_file".into(),
file_content: Some(ank_base::file::FileContent::BinaryData(
"base64_data".into(),
)),
},
],
}),
},
)]),
),
Expand Down Expand Up @@ -691,7 +787,23 @@ mod tests {
("ref2".into(), "config_2".into()),
]
.into()
})
}),
files: Some(ank_base::Files {
files: vec![
ank_base::File {
mount_point: "/file.json".into(),
file_content: Some(ank_base::file::FileContent::Data(
"text data".into()
)),
},
ank_base::File {
mount_point: "/binary_file".into(),
file_content: Some(ank_base::file::FileContent::BinaryData(
"base64_data".into()
)),
}
],
}),
},
)])
.into())
Expand Down Expand Up @@ -845,6 +957,22 @@ mod tests {
]
.into(),
}),
files: Some(ank_base::Files {
files: vec![
ank_base::File {
mount_point: "/file.json".into(),
file_content: Some(ank_base::file::FileContent::Data(
"text data".into(),
)),
},
ank_base::File {
mount_point: "/binary_file".into(),
file_content: Some(ank_base::file::FileContent::BinaryData(
"base64_data".into(),
)),
},
],
}),
},
)]),
)),
Expand Down
39 changes: 34 additions & 5 deletions common/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,19 @@ mod tests {

mod ank_base {
pub use api::ank_base::{
request::RequestContent, CompleteState, CompleteStateRequest, ConfigMappings,
Dependencies, Request, RestartPolicy, State, Tag, Tags, UpdateStateRequest, Workload,
WorkloadMap,
file::FileContent, request::RequestContent, CompleteState, CompleteStateRequest,
ConfigMappings, Dependencies, File, Files, Request, RestartPolicy, State, Tag, Tags,
UpdateStateRequest, Workload, WorkloadMap,
};
}

mod ankaios {
pub use crate::{
commands::{CompleteStateRequest, Request, RequestContent, UpdateStateRequest},
objects::{
generate_test_agent_map, generate_test_workload_states_map_with_data,
CompleteState, ExecutionState, RestartPolicy, State, StoredWorkloadSpec, Tag,
generate_test_agent_map, generate_test_workload_states_map_with_data, BinaryData,
CompleteState, Data, ExecutionState, File, FileContent, RestartPolicy, State,
StoredWorkloadSpec, Tag,
},
};
}
Expand Down Expand Up @@ -297,6 +298,20 @@ mod tests {
]
.into(),
}),
files: Some(ank_base::Files {
files: vec![
ank_base::File {
mount_point: "/file.json".into(),
file_content: Some(ank_base::FileContent::Data("text data".into())),
},
ank_base::File {
mount_point: "/binary_file".into(),
file_content: Some(ank_base::FileContent::BinaryData(
"base64_data".into(),
)),
},
],
}),
}
};
(ankaios) => {
Expand All @@ -316,6 +331,20 @@ mod tests {
("ref2".into(), "config_2".into()),
]
.into(),
files: vec![
ankaios::File {
mount_point: "/file.json".to_string(),
file_content: ankaios::FileContent::Data(ankaios::Data {
data: "text data".into(),
}),
},
ankaios::File {
mount_point: "/binary_file".to_string(),
file_content: ankaios::FileContent::BinaryData(ankaios::BinaryData {
binary_data: "base64_data".into(),
}),
},
],
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions common/src/objects/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ pub enum FileContent {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Data {
data: String,
pub data: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct BinaryData {
binary_data: String,
pub binary_data: String,
}

impl TryFrom<ank_base::File> for File {
Expand Down
2 changes: 1 addition & 1 deletion common/src/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ pub use config::generate_test_configs;
pub use config::ConfigItem;

mod file;
pub use file::File;
pub use file::{BinaryData, Data, File, FileContent};
19 changes: 17 additions & 2 deletions common/src/objects/stored_workload_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ use serde::{Deserialize, Serialize};
use crate::helpers::serialize_to_ordered_map;

use super::{
control_interface_access::ControlInterfaceAccess, file::File, AddCondition, RestartPolicy, Tag,
WorkloadInstanceName, WorkloadSpec,
control_interface_access::ControlInterfaceAccess,
file::{BinaryData, Data, File, FileContent},
AddCondition, RestartPolicy, Tag, WorkloadInstanceName, WorkloadSpec,
};

pub const STR_RE_CONFIG_REFERENCES: &str = r"^[a-zA-Z0-9_-]*$";
Expand Down Expand Up @@ -207,6 +208,20 @@ pub fn generate_test_stored_workload_spec_with_config(
("ref2".into(), "config_2".into()),
]
.into(),
files: vec![
File {
mount_point: "/file.json".to_string(),
file_content: FileContent::Data(Data {
data: "text data".into(),
}),
},
File {
mount_point: "/binary_file".to_string(),
file_content: FileContent::BinaryData(BinaryData {
binary_data: "base64_data".into(),
}),
},
],
}
}

Expand Down
16 changes: 15 additions & 1 deletion common/src/objects/workload_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::helpers::serialize_to_ordered_map;
use crate::objects::Tag;

use super::control_interface_access::ControlInterfaceAccess;
use super::file::File;
use super::file::{BinaryData, Data, File, FileContent};
use super::ExecutionState;
use super::WorkloadInstanceName;

Expand Down Expand Up @@ -316,6 +316,20 @@ pub fn generate_test_workload_spec_with_runtime_config(
}],
runtime_config,
control_interface_access: Default::default(),
files: vec![
File {
mount_point: "/file.json".to_string(),
file_content: FileContent::Data(Data {
data: "text data".into(),
}),
},
File {
mount_point: "/binary_file".to_string(),
file_content: FileContent::BinaryData(BinaryData {
binary_data: "base64_data".into(),
}),
},
],
}
}

Expand Down
22 changes: 20 additions & 2 deletions common/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,16 @@ pub fn generate_test_proto_workload_with_param(
configs: Some(ConfigMappings{configs: [
("ref1".into(), "config_1".into()),
("ref2".into(), "config_2".into()),
].into()})
].into()}),
files: Some(ank_base::Files {
files: vec![ank_base::File {
mount_point: "/file.json".into(),
file_content: Some(ank_base::file::FileContent::Data("text data".into())),
}, ank_base::File {
mount_point: "/binary_file".into(),
file_content: Some(ank_base::file::FileContent::BinaryData("base64_data".into())),
}],
}),
}
}

Expand All @@ -217,7 +226,16 @@ pub fn generate_test_proto_workload() -> ank_base::Workload {
configs: Some(ConfigMappings{configs: [
("ref1".into(), "config_1".into()),
("ref2".into(), "config_2".into()),
].into()})
].into()}),
files: Some(ank_base::Files {
files: vec![ank_base::File {
mount_point: "/file.json".into(),
file_content: Some(ank_base::file::FileContent::Data("text data".into())),
}, ank_base::File {
mount_point: "/binary_file".into(),
file_content: Some(ank_base::file::FileContent::BinaryData("base64_data".into())),
}],
}),
}
}

Expand Down
Loading

0 comments on commit afee47c

Please sign in to comment.