Skip to content

Commit

Permalink
providers/mock-tests: add mockito::reset and minor changes
Browse files Browse the repository at this point in the history
Signed-off-by: Allen Bai <[email protected]>
  • Loading branch information
Allen Bai committed Oct 10, 2019
1 parent cfffae4 commit 76753a5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
19 changes: 11 additions & 8 deletions src/providers/aws/mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ fn test_aws_basic() {
let _m = mockito::mock("GET", ep).with_status(404).create();
let v = provider.fetch_ssh_keys().unwrap();
assert_eq!(v.len(), 0);

mockito::reset();
provider.fetch_ssh_keys().unwrap_err();
}

#[test]
Expand Down Expand Up @@ -60,14 +63,14 @@ fn test_aws_attributes() {
}

let attributes = maplit::hashmap! {
format!("{}_INSTANCE_ID", aws::ENV_PREFIX) => String::from(instance_id),
format!("{}_INSTANCE_TYPE", aws::ENV_PREFIX) => String::from(instance_type),
format!("{}_IPV4_LOCAL", aws::ENV_PREFIX) => String::from(ipv4_local),
format!("{}_IPV4_PUBLIC", aws::ENV_PREFIX) => String::from(ipv4_public),
format!("{}_AVAILABILITY_ZONE", aws::ENV_PREFIX) => String::from(availability_zone),
format!("{}_HOSTNAME", aws::ENV_PREFIX) => String::from(hostname),
format!("{}_PUBLIC_HOSTNAME", aws::ENV_PREFIX) => String::from(public_hostname),
format!("{}_REGION", aws::ENV_PREFIX) => String::from(region),
format!("{}_INSTANCE_ID", aws::ENV_PREFIX) => instance_id.to_string(),
format!("{}_INSTANCE_TYPE", aws::ENV_PREFIX) => instance_type.to_string(),
format!("{}_IPV4_LOCAL", aws::ENV_PREFIX) => ipv4_local.to_string(),
format!("{}_IPV4_PUBLIC", aws::ENV_PREFIX) => ipv4_public.to_string(),
format!("{}_AVAILABILITY_ZONE", aws::ENV_PREFIX) => availability_zone.to_string(),
format!("{}_HOSTNAME", aws::ENV_PREFIX) => hostname.to_string(),
format!("{}_PUBLIC_HOSTNAME", aws::ENV_PREFIX) => public_hostname.to_string(),
format!("{}_REGION", aws::ENV_PREFIX) => region.to_string(),
};

let client = crate::retry::Client::try_new()
Expand Down
9 changes: 9 additions & 0 deletions src/providers/azure/mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ fn test_boot_checkin() {
m_goalstate.assert();
m_health.assert();
r.unwrap();

mockito::reset();
azure::Azure::try_new().unwrap_err();
}

#[test]
Expand All @@ -112,6 +115,9 @@ fn test_hostname() {
m_hostname.assert();
let hostname = r.unwrap();
assert_eq!(hostname, testname);

mockito::reset();
azure::Azure::try_new().unwrap_err();
}

#[test]
Expand All @@ -137,4 +143,7 @@ fn test_vmsize() {
m_vmsize.assert();
let vmsize = r.unwrap();
assert_eq!(vmsize, testvmsize);

mockito::reset();
azure::Azure::try_new().unwrap_err();
}
8 changes: 4 additions & 4 deletions src/providers/gcp/mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ fn basic_attributes() {
}

let attributes = maplit::hashmap! {
format!("{}_HOSTNAME", gcp::ENV_PREFIX) => String::from(hostname),
format!("{}_IP_EXTERNAL_0", gcp::ENV_PREFIX) => String::from(ip_external),
format!("{}_IP_LOCAL_0", gcp::ENV_PREFIX) => String::from(ip_local),
format!("{}_MACHINE_TYPE", gcp::ENV_PREFIX) => String::from(machine_type),
format!("{}_HOSTNAME", gcp::ENV_PREFIX) => hostname.to_string(),
format!("{}_IP_EXTERNAL_0", gcp::ENV_PREFIX) => ip_external.to_string(),
format!("{}_IP_LOCAL_0", gcp::ENV_PREFIX) => ip_local.to_string(),
format!("{}_MACHINE_TYPE", gcp::ENV_PREFIX) => machine_type.to_string(),
};

let client = crate::retry::Client::try_new()
Expand Down
16 changes: 9 additions & 7 deletions src/providers/packet/mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ fn test_boot_checkin() {
let r = provider.boot_checkin();
mock.assert();
r.unwrap();

mockito::reset();
provider.boot_checkin().unwrap_err();
}

#[test]
Expand All @@ -53,14 +56,10 @@ fn test_packet_attributes() {
"phone_home_url": "test-url"
}"#;

let hostname = "test-hostname";
let phone_home_url = "test-url";
let plan = "test-plan";

let attributes = maplit::hashmap! {
format!("PACKET_HOSTNAME") => String::from(hostname),
format!("PACKET_PHONE_HOME_URL") => String::from(phone_home_url),
format!("PACKET_PLAN") => String::from(plan),
"PACKET_HOSTNAME".to_string() => "test-hostname".to_string(),
"PACKET_PHONE_HOME_URL".to_string() => "test-url".to_string(),
"PACKET_PLAN".to_string() => "test-plan".to_string(),
};

let _m = mockito::mock("GET", "/metadata")
Expand All @@ -72,4 +71,7 @@ fn test_packet_attributes() {
let v = provider.attributes().unwrap();

assert_eq!(v, attributes);

mockito::reset();
packet::PacketProvider::try_new().unwrap_err();
}

0 comments on commit 76753a5

Please sign in to comment.