Skip to content

Commit

Permalink
[~] refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lebe-dev committed Nov 7, 2020
1 parent 16c98fe commit 50c7843
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/nginx_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pub mod nginx_tests {
use std::path::Path;

use crate::DEFAULT_HTTPS_PORT;
use crate::nginx::nginx::get_nginx_vhosts;
use crate::test_utils::test_utils::assert_vhost_in_vec;

Expand All @@ -19,7 +20,7 @@ pub mod nginx_tests {
let expected_size: usize = 2;
assert_eq!(&vhosts.len(), &expected_size);

assert_vhost_in_vec(&vhosts, SAMPLE_DOMAIN, 443);
assert_vhost_in_vec(&vhosts, SAMPLE_DOMAIN, DEFAULT_HTTPS_PORT);
assert_vhost_in_vec(&vhosts, SAMPLE_DOMAIN2, 23512);
}

Expand Down
25 changes: 16 additions & 9 deletions src/site_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod site_tests {
use crate::{DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT};
use crate::domain::domain::{Site, VirtualHost};
use crate::site::site::get_sites_from_vhosts;
use crate::test_samples::test_samples::{get_4_sample_vhosts, SAMPLE_DOMAIN2};
use crate::test_samples::test_samples::{get_4_sample_vhosts, SAMPLE_DOMAIN1, SAMPLE_DOMAIN2, SAMPLE_DOMAIN3, SAMPLE_DOMAIN4};

#[test]
fn without_www_domains_result_should_not_contain_domains_with_www_lol() {
Expand All @@ -14,7 +14,7 @@ mod site_tests {
assert_eq!(results.len(), 3);

let site_with_www_found =
results.iter().find(|site| site.url == "https://www.google.com");
results.iter().find(|site| site.url == "https://www.google.com");

assert!(site_with_www_found.is_none())
}
Expand All @@ -27,7 +27,8 @@ mod site_tests {

assert_eq!(results.len(), 4);

assert_site_with_url(&results, "https://www.google.com");
let expected_url = format!("https://{}", SAMPLE_DOMAIN4);
assert_site_with_url(&results, &expected_url);
}

#[test]
Expand All @@ -39,24 +40,28 @@ mod site_tests {

assert_eq!(results.len(), 1);

assert_site_with_url(&results, "https://dfov.ru");
let expected_url = format!("https://{}", SAMPLE_DOMAIN2);

assert_site_with_url(&results, &expected_url);
}

#[test]
fn vhost_with_standard_http_port_should_contain_http_prefix_for_url() {
let vhost1 = VirtualHost { domain: "tinyops.ru".to_string(), port: DEFAULT_HTTP_PORT };
let vhost1 = VirtualHost { domain: SAMPLE_DOMAIN3.to_string(), port: DEFAULT_HTTP_PORT };
let vhosts = vec![vhost1.clone()];

let results = get_sites_from_vhosts(vhosts, false);

assert_eq!(results.len(), 1);

assert_site_with_url(&results, "http://tinyops.ru");
let expected_url = format!("http://{}", SAMPLE_DOMAIN3);

assert_site_with_url(&results, &expected_url);
}

#[test]
fn vhost_with_non_standard_port_should_contain_http_prefix_for_url() {
let domain = "cronbox.ru";
let domain = SAMPLE_DOMAIN1;
let custom_port = 2345;
let vhost1 = VirtualHost { domain: domain.to_string(), port: custom_port };
let vhosts = vec![vhost1.clone()];
Expand All @@ -72,14 +77,16 @@ mod site_tests {

#[test]
fn site_name_without_https_should_contain_http_postfix() {
let vhost1 = VirtualHost { domain: "tinyops.ru".to_string(), port: DEFAULT_HTTP_PORT };
let vhost1 = VirtualHost { domain: SAMPLE_DOMAIN3.to_string(), port: DEFAULT_HTTP_PORT };
let vhosts = vec![vhost1.clone()];

let results = get_sites_from_vhosts(vhosts, false);

assert_eq!(results.len(), 1);

let site_found = results.iter().find(|site| site.name == "tinyops.ru_http");
let expected_site_name = format!("{}_http", SAMPLE_DOMAIN3);

let site_found = results.iter().find(|site| site.name == expected_site_name);
assert!(site_found.is_some())
}

Expand Down

0 comments on commit 50c7843

Please sign in to comment.