Skip to content

Commit

Permalink
feat: add fragment for config update
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Piotrowski <krzysztof.piotrowski@inetum.com>
  • Loading branch information
Ruadhri17 committed Feb 5, 2025
1 parent b603f85 commit 383ba81
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Context;
use c8y_api::smartrest::inventory::set_c8y_config_fragment;
use c8y_api::smartrest::smartrest_serializer::CumulocitySupportedOperations;
use tedge_api::commands::CommandStatus;
use tedge_api::commands::ConfigUpdateCmd;
Expand Down Expand Up @@ -47,14 +48,23 @@ impl OperationContext {
extra_messages: vec![],
}),
CommandStatus::Successful => {
let config_fragment = MqttMessage::new(
sm_topic,
set_c8y_config_fragment(
&command.payload.config_type,
&command.payload.remote_url,
Default::default(), // Config update payload is not provided with name field
),
);

let smartrest_operation_status = self.get_smartrest_successful_status_payload(
CumulocitySupportedOperations::C8yDownloadConfigFile,
cmd_id,
);
let c8y_notification = MqttMessage::new(sm_topic, smartrest_operation_status);

Ok(OperationOutcome::Finished {
messages: vec![c8y_notification],
messages: vec![config_fragment, c8y_notification],
})
}
CommandStatus::Failed { reason } => Err(anyhow::anyhow!(reason).into()),
Expand Down Expand Up @@ -371,6 +381,13 @@ mod tests {
.await
.expect("Send failed");

// Expect `120` smartrest message on `c8y/s/us`.
assert_received_contains_str(
&mut mqtt,
[("c8y/s/us", "120,path/type/A,http://www.my.url")],
)
.await;

// Expect `503` smartrest message on `c8y/s/us`.
assert_received_contains_str(&mut mqtt, [("c8y/s/us", "503,c8y_DownloadConfigFile")]).await;
}
Expand Down Expand Up @@ -408,6 +425,13 @@ mod tests {
.await
.expect("Send failed");

// Expect `120` smartrest message on `c8y/s/us`.
assert_received_contains_str(
&mut mqtt,
[("c8y/s/us/child1", "120,typeA,http://www.my.url")],
)
.await;

// Expect `503` smartrest message on child topic.
assert_received_contains_str(
&mut mqtt,
Expand Down Expand Up @@ -443,6 +467,13 @@ mod tests {
.await
.expect("Send failed");

// Expect `120` smartrest message on `c8y/s/us`.
assert_received_contains_str(
&mut mqtt,
[("c8y/s/us", "120,path/type/A,http://www.my.url")],
)
.await;

// Expect `503` smartrest message on `c8y/s/us`.
assert_received_contains_str(&mut mqtt, [("c8y/s/us", "506,1234")]).await;
}
Expand Down

0 comments on commit 383ba81

Please sign in to comment.