diff options
| author | Gus Power <gus@infinitesidequests.com> | 2025-05-12 10:52:28 +0100 |
|---|---|---|
| committer | Gus Power <gus@infinitesidequests.com> | 2025-05-12 10:52:28 +0100 |
| commit | 1d6fd8359fddbae8aeac17b90ed50d41143ffbb6 (patch) | |
| tree | 7872e1e112ea9ed440caecad9755da751de59ccd /src/test.rs | |
| parent | e1f43bb48b23338ce103dc92a53a13e72021299d (diff) | |
skeleton dyndns service, split into ip and dyndns modules
Diffstat (limited to 'src/test.rs')
| -rw-r--r-- | src/test.rs | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/src/test.rs b/src/test.rs deleted file mode 100644 index f2c4219..0000000 --- a/src/test.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::net::{IpAddr, Ipv4Addr}; -use reqwest::Url; -use wiremock::{Mock, MockServer, ResponseTemplate}; -use wiremock::matchers::{method, path}; -use crate::{IpService, IpServiceConfiguration}; - -async fn setup_ipv4_service(service_path: &str, response: &str) -> MockServer { - let ip_service = MockServer::start().await; - - Mock::given(method("GET")) - .and(path(service_path)) - .respond_with(ResponseTemplate::new(200) - .insert_header("Content-Type", "text/plain; charset=utf-8") - .set_body_string(response)) - .mount(&ip_service) - .await; - - ip_service -} - -#[tokio::test] -async fn successful_ipv4_address_resolution() { - let service_path = "get-my-ip-address"; - let service_response = "17.5.7.8"; - - let ip_service = setup_ipv4_service(service_path, service_response).await; - let service_config = TestIpServiceConfiguration::new(&ip_service, service_path); - - let actual = IpService::resolve(&service_config).await.unwrap(); - assert_eq!(actual, IpAddr::V4(Ipv4Addr::new(17, 5, 7, 8))) -} - -struct TestIpServiceConfiguration { - service_url: Url, -} - -impl TestIpServiceConfiguration { - fn new(server: &MockServer, path: &str) -> Self { - Self { - service_url: Url::parse(format!("{}/{}", server.uri(), path).as_str()).unwrap() - } - } -} -impl IpServiceConfiguration for TestIpServiceConfiguration { - fn get_service_url(&self) -> Url { - self.service_url.clone() - } -} |
