Skip to content

Commit f0363ae

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 a3a14d8 commit f0363ae

File tree

6 files changed

+683
-792
lines changed

6 files changed

+683
-792
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ astarte-message-hub-proto = { workspace = true, optional = true }
6666
base64 = { workspace = true }
6767
bson = { workspace = true, features = ["chrono-0_4"] }
6868
bytes = { workspace = true }
69+
cfg-if = { workspace = true }
6970
chrono = { workspace = true, features = ["serde"] }
7071
flate2 = { workspace = true }
7172
flume = { workspace = true, features = ["async"] }
@@ -98,6 +99,8 @@ reqwest = { workspace = true, features = ["macos-system-configuration"] }
9899

99100
[dev-dependencies]
100101
astarte-device-sdk-derive = { workspace = true }
102+
astarte-message-hub-proto = { workspace = true }
103+
astarte-message-hub-proto-mock = { workspace = true }
101104
async-trait = { workspace = true }
102105
color-eyre = { workspace = true }
103106
env_logger = { workspace = true }
@@ -131,11 +134,13 @@ rustc-args = ["--cfg=docsrs"]
131134
[workspace.dependencies]
132135
astarte-device-sdk = { path = "./", version = "=0.9.6" }
133136
astarte-device-sdk-derive = { version = "=0.9.6", path = "./astarte-device-sdk-derive" }
134-
astarte-message-hub-proto = { git = "https://github.com/astarte-platform/astarte-message-hub-proto", rev = "27f386114528ceeeb81440879f259146fbed6052" }
137+
astarte-message-hub-proto = { git = "https://github.com/astarte-platform/astarte-message-hub-proto", rev = "20ba40215172613bfab149676adf0dbd9f3ccc92" }
138+
astarte-message-hub-proto-mock = { git = "https://github.com/astarte-platform/astarte-message-hub-proto", rev = "20ba40215172613bfab149676adf0dbd9f3ccc92" }
135139
async-trait = "0.1.67"
136140
base64 = "0.22.0"
137141
bson = "2.7.0"
138142
bytes = "1.5.0"
143+
cfg-if = "1.0.0"
139144
chrono = "0.4.20"
140145
color-eyre = "0.6.3"
141146
env_logger = "0.11.0"

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ impl From<DeviceEvent> for astarte_message_hub_proto::AstarteMessage {
415415
}
416416
}
417417

418+
// TODO this is incomplete, no way of creating a PropertyIndividual with a set value
419+
// refactor value to include a property type or find a way of stashing that information
420+
// somewhere
418421
impl From<Value> for ProtoPayload {
419422
fn from(value: Value) -> Self {
420423
match value {
@@ -463,6 +466,16 @@ pub(crate) mod test {
463466
}
464467
}
465468

469+
pub(crate) fn new_property(
470+
path: String,
471+
data: Option<AstarteType>,
472+
) -> astarte_message_hub_proto::Property {
473+
astarte_message_hub_proto::Property {
474+
path,
475+
data: data.map(|s| s.into()),
476+
}
477+
}
478+
466479
#[test]
467480
fn proto_astarte_double_into_astarte_device_sdk_type_success() {
468481
let value = 15.5;

0 commit comments

Comments
 (0)