Skip to content

Commit

Permalink
Add deployment info testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kurotych committed Nov 19, 2024
1 parent 6cc2aa9 commit 912423f
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions mobile_config/tests/gateway_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use futures::stream::StreamExt;

use helium_crypto::{KeyTag, Keypair, PublicKey, PublicKeyBinary, Sign};
use helium_proto::services::mobile_config::{
self as proto, DeviceType, GatewayClient, GatewayInfoStreamReqV1, GatewayInfoStreamResV1,
self as proto, gateway_metadata::DeploymentInfo, DeviceType, GatewayClient,
GatewayInfoStreamReqV1, GatewayInfoStreamResV1,
};
use mobile_config::{
gateway_service::GatewayService,
Expand Down Expand Up @@ -126,6 +127,7 @@ async fn gateway_stream_info_refreshed_at(pool: PgPool) {
asset1_pubkey.clone().into(),
now,
Some(now),
None,
)
.await;
add_db_record(
Expand All @@ -136,6 +138,7 @@ async fn gateway_stream_info_refreshed_at(pool: PgPool) {
asset2_pubkey.clone().into(),
now_plus_10,
Some(now_plus_10),
None,
)
.await;

Expand Down Expand Up @@ -199,6 +202,7 @@ async fn gateway_stream_info_refreshed_at_is_null(pool: PgPool) {
asset1_pubkey.clone().into(),
now,
None,
None,
)
.await;

Expand Down Expand Up @@ -238,6 +242,7 @@ async fn gateway_stream_info_data_types(pool: PgPool) {
asset1_pubkey.clone().into(),
now,
Some(now),
Some(r#"{"wifiInfoV0": {"antenna": 18, "azimuth": 160, "elevation": 5, "electricalDownTilt": 1, "mechanicalDownTilt": 2}}"#)
)
.await;
add_db_record(
Expand All @@ -248,6 +253,8 @@ async fn gateway_stream_info_data_types(pool: PgPool) {
asset2_pubkey.clone().into(),
now,
Some(now),
// Should be returned None in deployment info
Some(r#"{"wifiInfoV0Invalid": {"antenna": 18}}"#),
)
.await;
add_db_record(
Expand All @@ -258,6 +265,7 @@ async fn gateway_stream_info_data_types(pool: PgPool) {
asset3_pubkey.clone().into(),
now,
Some(now),
None,
)
.await;

Expand Down Expand Up @@ -312,12 +320,32 @@ async fn gateway_stream_info_data_types(pool: PgPool) {
.collect::<Vec<GatewayInfoStreamResV1>>()
.await;
let gateways = resp.first().unwrap().gateways.clone();
assert_eq!(gateways.len(), 3);

// TODO Check deployment info
let _gw = gateways.first().unwrap();
// Check deployment info
assert_eq!(gateways.len(), 3);
for gw in gateways {
if let Some(metadata) = &gw.metadata {
if DeviceType::try_from(gw.device_type).unwrap() != DeviceType::WifiIndoor {
assert!(metadata.deployment_info.is_none());
}

if let Some(deployment_info) = &metadata.deployment_info {
match deployment_info {
DeploymentInfo::WifiDeploymentInfo(v) => {
assert_eq!(v.antenna, 18);
assert_eq!(v.azimuth, 160);
assert_eq!(v.elevation, 5);
assert_eq!(v.electrical_down_tilt, 1);
assert_eq!(v.mechanical_down_tilt, 2);
}
DeploymentInfo::CbrsDeploymentInfo(_) => panic!(),
};
}
}
}
}

#[allow(clippy::too_many_arguments)]
async fn add_db_record(
pool: &PgPool,
asset: &str,
Expand All @@ -326,8 +354,18 @@ async fn add_db_record(
key: PublicKeyBinary,
created_at: DateTime<Utc>,
refreshed_at: Option<DateTime<Utc>>,
deployment_info: Option<&str>,
) {
add_mobile_hotspot_infos(pool, asset, location, device_type, created_at, refreshed_at).await;
add_mobile_hotspot_infos(
pool,
asset,
location,
device_type,
created_at,
refreshed_at,
deployment_info,
)
.await;
add_asset_key(pool, asset, key).await;
}

Expand All @@ -338,6 +376,7 @@ async fn add_mobile_hotspot_infos(
device_type: &str,
created_at: DateTime<Utc>,
refreshed_at: Option<DateTime<Utc>>,
deployment_info: Option<&str>,
) {
sqlx::query(
r#"
Expand All @@ -352,7 +391,7 @@ async fn add_mobile_hotspot_infos(
.bind(device_type)
.bind(created_at)
.bind(refreshed_at)
.bind(r#"{"wifiInfoV0": {"antenna": 18, "azimuth": 160, "elevation": 5, "electricalDownTilt": 1, "mechanicalDownTilt": 2}}"#)
.bind(deployment_info)
.execute(pool)
.await
.unwrap();
Expand Down

0 comments on commit 912423f

Please sign in to comment.