Skip to content

Commit

Permalink
chore: change tests so that we can add fields to clientapplication wi…
Browse files Browse the repository at this point in the history
…thout a lot of noise (#39)
  • Loading branch information
sighphyre authored Jul 18, 2024
1 parent 12fc7c0 commit 29a3068
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/client_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ mod tests {

use super::*;

impl Default for ClientApplication {
fn default() -> Self {
Self {
app_name: Default::default(),
connect_via: Default::default(),
environment: Default::default(),
instance_id: Default::default(),
interval: Default::default(),
sdk_version: Default::default(),
started: Default::default(),
strategies: Default::default(),
}
}
}

#[test]
pub fn can_increment_counts() {
let mut stats = ToggleStats::default();
Expand Down Expand Up @@ -280,14 +295,14 @@ mod tests {
pub fn merging_two_client_applications_should_use_set_values() {
let demo_data_orig = ClientApplication::new("demo", 15000);
let demo_data_with_more_data = ClientApplication {
connect_via: None,
app_name: "demo".into(),
interval: 15500,
environment: Some("development".into()),
instance_id: Some("instance_id".into()),
sdk_version: Some("unleash-client-java:7.1.0".into()),
started: Utc::now(),
strategies: vec!["default".into(), "gradualRollout".into()],
..Default::default()
};
// Cloning orig here, to avoid the destructive merge preventing us from testing
let merged = demo_data_orig.clone().merge(demo_data_with_more_data);
Expand All @@ -303,25 +318,21 @@ mod tests {
pub fn merging_two_client_applications_prioritizes_left_hand_side() {
let started = Utc::now();
let demo_data_1 = ClientApplication {
connect_via: None,
app_name: "demo".into(),
interval: 15500,
environment: None,
instance_id: None,
sdk_version: Some("unleash-client-java:7.1.0".into()),
started,
strategies: vec!["default".into(), "gradualRollout".into()],
..Default::default()
};

let demo_data_2 = ClientApplication {
connect_via: None,
app_name: "demo".into(),
interval: 15500,
environment: Some("production".into()),
instance_id: None,
sdk_version: None,
started,
strategies: vec!["default".into(), "CustomStrategy".into()],
..Default::default()
};

let left = demo_data_2.clone().merge(demo_data_1.clone());
Expand All @@ -333,14 +344,12 @@ mod tests {
#[test]
pub fn can_connect_via_new_application() {
let demo_data = ClientApplication {
connect_via: None,
app_name: "demo".into(),
interval: 15500,
environment: Some("production".into()),
instance_id: None,
sdk_version: None,
started: Utc::now(),
strategies: vec!["default".into(), "CustomStrategy".into()],
..Default::default()
};
let connected_via = demo_data.connect_via("unleash-edge", "edge-id-1");
assert_eq!(
Expand All @@ -362,11 +371,10 @@ mod tests {
}]),
app_name: "demo".into(),
interval: 15500,
environment: None,
instance_id: None,
sdk_version: Some("unleash-client-java:7.1.0".into()),
started,
strategies: vec!["default".into(), "gradualRollout".into()],
..Default::default()
};

let demo_data_2 = ClientApplication {
Expand All @@ -377,10 +385,9 @@ mod tests {
app_name: "demo".into(),
interval: 15500,
environment: Some("production".into()),
instance_id: None,
sdk_version: None,
started,
strategies: vec!["default".into(), "CustomStrategy".into()],
..Default::default()
};

let merged = demo_data_1.merge(demo_data_2);
Expand All @@ -405,14 +412,12 @@ mod tests {
pub fn can_merge_connected_via_where_one_side_is_none() {
let started = Utc::now();
let demo_data_1 = ClientApplication {
connect_via: None,
app_name: "demo".into(),
interval: 15500,
environment: None,
instance_id: None,
sdk_version: Some("unleash-client-java:7.1.0".into()),
started,
strategies: vec!["default".into(), "gradualRollout".into()],
..Default::default()
};

let demo_data_2 = ClientApplication {
Expand All @@ -423,10 +428,9 @@ mod tests {
app_name: "demo".into(),
interval: 15500,
environment: Some("production".into()),
instance_id: None,
sdk_version: None,
started,
strategies: vec!["default".into(), "CustomStrategy".into()],
..Default::default()
};
let merged = demo_data_1.clone().merge(demo_data_2.clone());
assert_eq!(demo_data_2.connect_via, merged.connect_via);
Expand Down

0 comments on commit 29a3068

Please sign in to comment.