|
| 1 | +use opengit::format::{AddressType, format_git_url, get_domain_type, get_git_remote_url}; |
| 2 | + |
| 3 | +#[test] |
| 4 | +fn domain_type_test() { |
| 5 | + let input = "github.com"; |
| 6 | + let expected = AddressType::DomainName; |
| 7 | + assert_eq!(get_domain_type(input), expected); |
| 8 | +} |
| 9 | +#[test] |
| 10 | +fn ip_type_test() { |
| 11 | + let input = "192.168.1.1"; |
| 12 | + let expected = AddressType::IpAddress; |
| 13 | + assert_eq!(get_domain_type(input), expected); |
| 14 | +} |
| 15 | +#[test] |
| 16 | +fn invalid_domain_type_test1() { |
| 17 | + let input = "localhost"; |
| 18 | + let expected = AddressType::Invalid; |
| 19 | + assert_eq!(get_domain_type(input), expected); |
| 20 | +} |
| 21 | +#[test] |
| 22 | +fn invalid_domain_type_test2() { |
| 23 | + let input = "192-189-11-111"; |
| 24 | + let expected = AddressType::Invalid; |
| 25 | + assert_eq!(get_domain_type(input), expected); |
| 26 | +} |
| 27 | +#[test] |
| 28 | +fn invalid_domain_type_test3() { |
| 29 | + let input = "255.255.255.259"; |
| 30 | + let expected = AddressType::Invalid; |
| 31 | + assert_eq!(get_domain_type(input), expected); |
| 32 | +} |
| 33 | + |
| 34 | +#[test] |
| 35 | +fn format_git_url_https_test() { |
| 36 | + let input = "https://github.com/log1997/opengit.git".to_string(); |
| 37 | + let expected = "https://github.com/log1997/opengit"; |
| 38 | + assert_eq!(format_git_url(input), expected); |
| 39 | +} |
| 40 | + |
| 41 | +#[test] |
| 42 | +fn format_git_url_git_test() { |
| 43 | + let input = "git@github.com:log1997/opengit.git".to_string(); |
| 44 | + let expected = "https://github.com/log1997/opengit"; |
| 45 | + assert_eq!(format_git_url(input), expected); |
| 46 | +} |
| 47 | + |
| 48 | +#[test] |
| 49 | +fn format_git_url_gitee_test() { |
| 50 | + let input = "https://gitee.com/log1997/opengit.git".to_string(); |
| 51 | + let expected = "https://gitee.com/log1997/opengit"; |
| 52 | + assert_eq!(format_git_url(input), expected); |
| 53 | +} |
| 54 | + |
| 55 | +#[test] |
| 56 | +fn format_git_url_no_git_test() { |
| 57 | + let input = "https://gitee.com/log1997/opengit".to_string(); |
| 58 | + let expected = "https://gitee.com/log1997/opengit"; |
| 59 | + assert_eq!(format_git_url(input), expected); |
| 60 | +} |
| 61 | + |
| 62 | +#[test] |
| 63 | +fn format_git_url_number_ip_test() { |
| 64 | + let input = "git@10.2.3.12:log1997/opengit.git".to_string(); |
| 65 | + let expected = "http://10.2.3.12/log1997/opengit"; |
| 66 | + assert_eq!(format_git_url(input), expected); |
| 67 | +} |
| 68 | + |
| 69 | +#[test] |
| 70 | +fn get_git_remote_url_test() { |
| 71 | + let expected = "git@github.com:LOG1997/opengit.git"; |
| 72 | + assert_eq!(get_git_remote_url(), Some(expected.to_string())); |
| 73 | +} |
0 commit comments