-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Labels
enhancementNew feature or request. Issue will appear in the change log "Features"New feature or request. Issue will appear in the change log "Features"
Milestone
Description
Description
Currently, there are fixtures in the api crate that serve all around ankaios with the purpose of easily creating standardized proto and spec objects, to be used within the tests.
When we will release the api as a crate, it would be better to not have them present, the goal being to keep only what is required, and not additional functions that do not serve anybody else.
Goals
The current fixtured cannot be implemented elsewhere, they are implemented with traits.
- Find a way to implement the fixtures in a standardized way, such that the fixtures can be moved outside the api.
- Remove any trace of the fixtures from the api and remove the
test_utilsfeature of the api crate (which will no longer be needed)
Tips
A solution to the fixtures is by using macros (which were implemented in the common/src/commands.rs) which can build any object based on a specific parameter. Here are some examples of such macros:
const WORKLOAD_NAME_1: &str = "workload_name_1";
const WORKLOAD_NAME_2: &str = "workload_name_2";
const INSTANCE_ID_1: &str = "instance_id_1";
const INSTANCE_ID_2: &str = "instance_id_2";
const AGENT_NAME: &str = "agent_1";
macro_rules! workload_name {
($number:literal) => {
[WORKLOAD_NAME_1, WORKLOAD_NAME_2][$number - 1]
};
}
macro_rules! instance_id {
($number:literal) => {
[INSTANCE_ID_1, INSTANCE_ID_2][$number - 1]
};
}
macro_rules! workload_instance_name {
(ank_base, $number:expr) => {
WorkloadInstanceName {
agent_name: AGENT_NAME.into(),
workload_name: workload_name!($number).into(),
id: instance_id!($number).into(),
}
};
(ankaios, $number:expr) => {
WorkloadInstanceNameSpec {
workload_name: workload_name!($number).to_owned(),
agent_name: AGENT_NAME.to_owned(),
id: instance_id!($number).to_owned(),
}
};
}
macro_rules! workload {
(ank_base) => {
Workload {
agent: Some(AGENT_NAME.to_string()),
runtime: RUNTIME.to_string(),
dependencies: Some(Dependencies::default()),
...
}
};
(ankaios) => {
WorkloadSpec {
agent: AGENT_NAME.to_string(),
runtime: RUNTIME.to_string(),
dependencies: Default::default(),
...
}
};
}Final result
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request. Issue will appear in the change log "Features"New feature or request. Issue will appear in the change log "Features"
Type
Projects
Status
No status