Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
argerus committed Jun 19, 2023
1 parent ddc1fb9 commit 47b5fff
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions kuksa_databroker/databroker/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,11 +913,11 @@ impl<'a, 'b> DatabaseWriteAccess<'a, 'b> {
pub fn update(&mut self, id: i32, update: EntryUpdate) -> Result<HashSet<Field>, UpdateError> {
match self.db.entries.get_mut(&id) {
Some(entry) => {
if update.entry_type.is_some()
if update.path.is_some()
|| update.entry_type.is_some()
|| update.data_type.is_some()
|| update.description.is_some()
{
// Should this not rather be some error, "FaultyAPIUse" or similar?
return Err(UpdateError::PermissionDenied);
}
match (
Expand Down
7 changes: 1 addition & 6 deletions kuksa_databroker/databroker/src/grpc/kuksa_val_v1/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,6 @@ impl broker::EntryUpdate {
entry: &proto::DataEntry,
fields: HashSet<proto::Field>,
) -> Self {
let path = if fields.contains(&proto::Field::Path) {
Some(entry.path.clone())
} else {
None
};
let datapoint = if fields.contains(&proto::Field::Value) {
entry
.value
Expand All @@ -542,7 +537,7 @@ impl broker::EntryUpdate {
None
};
Self {
path,
path: None,
datapoint,
actuator_target,
entry_type: None,
Expand Down
22 changes: 15 additions & 7 deletions kuksa_databroker/databroker/src/grpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ where
pub async fn serve_with_incoming_shutdown<F>(
stream: TcpListenerStream,
broker: broker::DataBroker,
authorization: Authorization,
signal: F,
) -> Result<(), Box<dyn std::error::Error>>
where
Expand All @@ -162,15 +163,22 @@ where
Server::builder()
.http2_keepalive_interval(Some(Duration::from_secs(10)))
.http2_keepalive_timeout(Some(Duration::from_secs(20)))
.add_service(sdv::databroker::v1::broker_server::BrokerServer::with_interceptor(
broker.clone(),
Authorization::Disabled,
))
.add_service(sdv::databroker::v1::collector_server::CollectorServer::with_interceptor(
.add_service(
sdv::databroker::v1::broker_server::BrokerServer::with_interceptor(
broker.clone(),
authorization.clone(),
),
)
.add_service(
sdv::databroker::v1::collector_server::CollectorServer::with_interceptor(
broker.clone(),
authorization.clone(),
),
)
.add_service(kuksa::val::v1::val_server::ValServer::with_interceptor(
broker.clone(),
Authorization::Disabled,
authorization,
))
.add_service(kuksa::val::v1::val_server::ValServer::with_interceptor(broker.clone(),Authorization::Disabled))
.serve_with_incoming_shutdown(stream, shutdown(broker, signal))
.await?;

Expand Down
12 changes: 4 additions & 8 deletions kuksa_databroker/databroker/tests/current_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{future, time::SystemTime, vec};

use cucumber::{cli, given, then, when, writer, World as _};
use databroker_proto::kuksa::val::v1::{
datapoint::Value, DataEntry, DataType, Datapoint, EntryRequest, EntryType, EntryUpdate, Field,
GetRequest, Metadata, SetRequest, View,
datapoint::Value, DataEntry, DataType, Datapoint, EntryRequest, EntryUpdate, Field, GetRequest,
SetRequest, View,
};
use tracing::debug;
use world::DataBrokerWorld;
Expand Down Expand Up @@ -51,11 +51,7 @@ async fn set_current_value(
path: path.clone(),
value: Some(datapoint),
actuator_target: None,
metadata: Some(Metadata {
data_type: data_type.into(),
entry_type: EntryType::Sensor.into(),
..Default::default()
}),
metadata: None,
}),
fields: vec![Field::Value.into(), Field::Path.into()],
}],
Expand Down Expand Up @@ -158,7 +154,7 @@ fn assert_set_request_failure(w: &mut DataBrokerWorld, path: String, expected_er

#[tokio::main]
async fn main() {
databroker::init_logging();
// databroker::init_logging();

let opts = cli::Opts::<_, _, _, world::UnsupportedLibtestArgs>::parsed();

Expand Down
5 changes: 3 additions & 2 deletions kuksa_databroker/databroker/tests/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ const DATAPOINTS: &[(
#[derive(clap::Args)] // re-export of `clap::Args`
pub struct UnsupportedLibtestArgs {
#[arg(long)]
report_time: bool,
report_time: Option<bool>,
#[arg(long)]
test_threads: u16,
test_threads: Option<u16>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -195,6 +195,7 @@ impl DataBrokerWorld {
grpc::server::serve_with_incoming_shutdown(
tokio_stream::wrappers::TcpListenerStream::new(listener),
data_broker,
grpc::server::Authorization::Disabled,
poll_fn(|cx| {
let mut state = owned_state
.lock()
Expand Down

0 comments on commit 47b5fff

Please sign in to comment.