Skip to content

Commit bb608bd

Browse files
committed
refactor(grpc): Refactor grpc test
Reworked to make use of the mock exported in the astarte_message_hub_proto_mock crate. Removed controversial template macro. Signed-off-by: Luca Arato <luca.arato@secomind.com>
1 parent a1e6441 commit bb608bd

File tree

6 files changed

+685
-804
lines changed

6 files changed

+685
-804
lines changed

Cargo.lock

Lines changed: 45 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ reqwest = { workspace = true, features = ["macos-system-configuration"] }
8686

8787
[dev-dependencies]
8888
astarte-device-sdk-derive = { workspace = true }
89+
astarte-message-hub-proto = { workspace = true }
90+
astarte-message-hub-proto-mock = { workspace = true }
8991
async-trait = { workspace = true }
9092
color-eyre = { workspace = true }
9193
env_logger = { workspace = true }

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ mod test {
108108
pub(crate) const E2E_DEVICE_DATASTREAM: &str = include_str!(
109109
"../e2e-test/interfaces/org.astarte-platform.rust.e2etest.DeviceDatastream.json"
110110
);
111+
pub(crate) const E2E_SERVER_DATASTREAM: &str = include_str!(
112+
"../e2e-test/interfaces/org.astarte-platform.rust.e2etest.ServerAggregate.json"
113+
);
111114
pub(crate) const E2E_DEVICE_AGGREGATE: &str = include_str!(
112115
"../e2e-test/interfaces/org.astarte-platform.rust.e2etest.DeviceAggregate.json"
113116
);

src/transport/grpc/convert.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ impl From<DeviceEvent> for astarte_message_hub_proto::AstarteMessage {
410410
}
411411
}
412412

413+
// TODO this is incomplete, no way of creating a PropertyIndividual with a set value
414+
// refactor value to include a property type or find a way of stashing that information
415+
// somewhere
413416
impl From<Value> for ProtoPayload {
414417
fn from(value: Value) -> Self {
415418
match value {
@@ -446,10 +449,6 @@ pub(crate) mod test {
446449

447450
use super::*;
448451

449-
pub(crate) fn new_unset() -> ProtoPayload {
450-
ProtoPayload::PropertyIndividual(AstartePropertyIndividual { data: None })
451-
}
452-
453452
pub(crate) fn new_astarte_message(
454453
interface_name: String,
455454
path: String,
@@ -464,6 +463,16 @@ pub(crate) mod test {
464463
}
465464
}
466465

466+
pub(crate) fn new_property(
467+
path: String,
468+
data: Option<AstarteType>,
469+
) -> astarte_message_hub_proto::Property {
470+
astarte_message_hub_proto::Property {
471+
path,
472+
data: data.map(|s| s.into()),
473+
}
474+
}
475+
467476
#[test]
468477
fn proto_astarte_double_into_astarte_device_sdk_type_success() {
469478
let value = 15.5;

0 commit comments

Comments
 (0)