Skip to content

Commit fb1aed7

Browse files
committed
Capture calls to augment_electrical_component_bounds
Signed-off-by: Simon Völcker <simon.voelcker@frequenz.com>
1 parent cf5d254 commit fb1aed7

2 files changed

Lines changed: 33 additions & 13 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ tonic = "0.14"
2323
tonic-prost = "0.14"
2424
tracing = { version = "0.1" }
2525
tracing-subscriber = { version = "0.3" }
26+
tokio-stream = { version = "0.1.17", features = ["sync"] }
2627

2728
[dev-dependencies]
2829
tracing-subscriber = { version = "0.3", features = ["std", "env-filter"] }
2930
tokio = { version = "1.48", features = ["test-util"] }
30-
tokio-stream = { version = "0.1.17", features = ["sync"] }
3131

3232

3333
[build-dependencies]

src/client/test_utils.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@
33

44
//! A mock implementation of the MicrogridApiClient for testing.
55
6+
use std::sync::Mutex;
67
use std::{sync::Arc, time::SystemTime};
7-
88
use tokio_stream::wrappers::ReceiverStream;
99
use tonic::Response;
1010

11+
use super::MicrogridApiClient;
1112
use crate::{
1213
proto::{
1314
common::{
1415
metrics::{
15-
Bounds, Metric, MetricSample, MetricValueVariant, SimpleMetricValue, metric_value_variant,
16+
Bounds, Metric, MetricSample, MetricValueVariant, SimpleMetricValue,
17+
metric_value_variant,
1618
},
1719
microgrid::electrical_components::{
1820
ElectricalComponent, ElectricalComponentCategory,
1921
ElectricalComponentCategorySpecificInfo, ElectricalComponentConnection,
2022
ElectricalComponentStateCode, ElectricalComponentStateSnapshot,
21-
ElectricalComponentTelemetry, Inverter, InverterType,
23+
ElectricalComponentTelemetry, Inverter, InverterType, MetricConfigBounds,
2224
electrical_component_category_specific_info::Kind,
23-
MetricConfigBounds,
2425
},
2526
},
2627
google::protobuf,
@@ -34,7 +35,6 @@ use crate::{
3435
},
3536
quantity::{Current, Power, ReactivePower, Voltage},
3637
};
37-
use super::MicrogridApiClient;
3838

3939
/// A mock implementation of the `MicrogridApiClient` trait for testing purposes.
4040
///
@@ -43,6 +43,7 @@ use super::MicrogridApiClient;
4343
pub struct MockMicrogridApiClient {
4444
pub components: Vec<Arc<MockComponent>>,
4545
pub connections: Vec<ElectricalComponentConnection>,
46+
pub augment_bounds_calls: Arc<Mutex<Vec<AugmentElectricalComponentBoundsRequest>>>,
4647
}
4748

4849
#[derive(Default, Debug, Clone)]
@@ -162,13 +163,18 @@ impl MockComponent {
162163
self
163164
}
164165

165-
pub fn add_component_bounds(mut self, metric: i32, lower: Option<f32>, upper: Option<f32>) -> Self {
166-
self.component.metric_config_bounds.push(
167-
MetricConfigBounds {
166+
pub fn add_component_bounds(
167+
mut self,
168+
metric: i32,
169+
lower: Option<f32>,
170+
upper: Option<f32>,
171+
) -> Self {
172+
self.component
173+
.metric_config_bounds
174+
.push(MetricConfigBounds {
168175
metric,
169-
config_bounds: Some(Bounds {lower, upper}),
170-
}
171-
);
176+
config_bounds: Some(Bounds { lower, upper }),
177+
});
172178
self
173179
}
174180

@@ -242,6 +248,7 @@ impl MockMicrogridApiClient {
242248
let mut this_client = Self {
243249
components: vec![],
244250
connections: vec![],
251+
augment_bounds_calls: Arc::new(Mutex::new(Vec::new())),
245252
};
246253

247254
let now = SystemTime::now();
@@ -283,6 +290,13 @@ impl MockMicrogridApiClient {
283290

284291
this_client
285292
}
293+
294+
/// Return a handle to captured augment bounds requests.
295+
pub fn augment_bounds_calls_handle(
296+
&self,
297+
) -> Arc<Mutex<Vec<AugmentElectricalComponentBoundsRequest>>> {
298+
self.augment_bounds_calls.clone()
299+
}
286300
}
287301

288302
#[async_trait::async_trait]
@@ -458,7 +472,13 @@ impl MicrogridApiClient for MockMicrogridApiClient {
458472
_request: impl tonic::IntoRequest<AugmentElectricalComponentBoundsRequest> + Send,
459473
) -> std::result::Result<tonic::Response<AugmentElectricalComponentBoundsResponse>, tonic::Status>
460474
{
461-
unimplemented!()
475+
// Capture calls for tests
476+
let req = _request.into_request().into_inner();
477+
self.augment_bounds_calls.lock().unwrap().push(req);
478+
479+
Ok(Response::new(AugmentElectricalComponentBoundsResponse {
480+
valid_until_time: None,
481+
}))
462482
}
463483
}
464484

0 commit comments

Comments
 (0)