From 76753a5b8723818412c434b65ee632f7a8e94b21 Mon Sep 17 00:00:00 2001 From: Allen Bai Date: Thu, 10 Oct 2019 10:45:10 -0400 Subject: [PATCH] providers/mock-tests: add mockito::reset and minor changes Signed-off-by: Allen Bai --- src/providers/aws/mock_tests.rs | 19 +++++++++++-------- src/providers/azure/mock_tests.rs | 9 +++++++++ src/providers/gcp/mock_tests.rs | 8 ++++---- src/providers/packet/mock_tests.rs | 16 +++++++++------- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/providers/aws/mock_tests.rs b/src/providers/aws/mock_tests.rs index 380fea43..d09837c6 100644 --- a/src/providers/aws/mock_tests.rs +++ b/src/providers/aws/mock_tests.rs @@ -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] @@ -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() diff --git a/src/providers/azure/mock_tests.rs b/src/providers/azure/mock_tests.rs index 554cacff..b3c3f153 100644 --- a/src/providers/azure/mock_tests.rs +++ b/src/providers/azure/mock_tests.rs @@ -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] @@ -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] @@ -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(); } diff --git a/src/providers/gcp/mock_tests.rs b/src/providers/gcp/mock_tests.rs index d9328815..7c3b5f27 100644 --- a/src/providers/gcp/mock_tests.rs +++ b/src/providers/gcp/mock_tests.rs @@ -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() diff --git a/src/providers/packet/mock_tests.rs b/src/providers/packet/mock_tests.rs index dce47a6f..eeb76d92 100644 --- a/src/providers/packet/mock_tests.rs +++ b/src/providers/packet/mock_tests.rs @@ -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] @@ -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") @@ -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(); }