Refactor application structure and simplify implementation
This commit is contained in:
@@ -208,6 +208,7 @@ fn selects_server_from_cached_subscription() {
|
||||
let status = select_singbox_server_in_storage(
|
||||
&storage,
|
||||
SelectSingBoxServerInputDto {
|
||||
id: Some("trojan|de-1|de.example.test|443".to_string()),
|
||||
tag: "de-1".to_string(),
|
||||
server: None,
|
||||
server_port: None,
|
||||
@@ -220,7 +221,47 @@ fn selects_server_from_cached_subscription() {
|
||||
.expect("read local sing-box config");
|
||||
|
||||
assert_eq!(status.config.selected_server_tag, Some("de-1".to_string()));
|
||||
assert_eq!(
|
||||
status.config.selected_server_id,
|
||||
Some("trojan|de-1|de.example.test|443".to_string())
|
||||
);
|
||||
assert_eq!(config.selected_server_tag, Some("de-1".to_string()));
|
||||
assert_eq!(
|
||||
config.selected_server_id,
|
||||
Some("trojan|de-1|de.example.test|443".to_string())
|
||||
);
|
||||
|
||||
cleanup(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selects_duplicate_tag_by_stable_server_id() {
|
||||
let root = test_root("select-duplicate-tag");
|
||||
let storage = JsonStorage::new(root.clone());
|
||||
let mut cache = sample_cache();
|
||||
cache.servers[1].tag = "nl-1".to_string();
|
||||
cache.servers[1].id = "trojan|nl-1|de.example.test|443".to_string();
|
||||
storage
|
||||
.write_singbox_subscription_cache(&cache)
|
||||
.expect("write cache");
|
||||
|
||||
let status = select_singbox_server_in_storage(
|
||||
&storage,
|
||||
SelectSingBoxServerInputDto {
|
||||
id: Some("trojan|nl-1|de.example.test|443".to_string()),
|
||||
tag: "nl-1".to_string(),
|
||||
server: Some("de.example.test".to_string()),
|
||||
server_port: Some(443),
|
||||
},
|
||||
&FixedClock,
|
||||
)
|
||||
.expect("stable id should select the second duplicate tag");
|
||||
|
||||
assert_eq!(
|
||||
status.config.selected_server_id,
|
||||
Some("trojan|nl-1|de.example.test|443".to_string())
|
||||
);
|
||||
assert_eq!(status.config.selected_server_tag, Some("nl-1".to_string()));
|
||||
|
||||
cleanup(&root);
|
||||
}
|
||||
@@ -236,6 +277,7 @@ fn selects_server_by_endpoint_when_display_tag_is_sanitized() {
|
||||
let status = select_singbox_server_in_storage(
|
||||
&storage,
|
||||
SelectSingBoxServerInputDto {
|
||||
id: None,
|
||||
tag: "Умный".to_string(),
|
||||
server: Some("media.example.test".to_string()),
|
||||
server_port: Some(443),
|
||||
@@ -465,12 +507,14 @@ fn sample_cache() -> SubscriptionCache {
|
||||
}),
|
||||
servers: vec![
|
||||
SubscriptionServer {
|
||||
id: "vless|nl-1|nl.example.test|443".to_string(),
|
||||
tag: "nl-1".to_string(),
|
||||
server_type: "vless".to_string(),
|
||||
server: "nl.example.test".to_string(),
|
||||
server_port: 443,
|
||||
},
|
||||
SubscriptionServer {
|
||||
id: "trojan|de-1|de.example.test|443".to_string(),
|
||||
tag: "de-1".to_string(),
|
||||
server_type: "trojan".to_string(),
|
||||
server: "de.example.test".to_string(),
|
||||
@@ -496,6 +540,7 @@ fn sample_cache_with_flag_tag() -> SubscriptionCache {
|
||||
]
|
||||
}),
|
||||
servers: vec![SubscriptionServer {
|
||||
id: "vless|Умный 🇳🇱->🇷🇺|media.example.test|443".to_string(),
|
||||
tag: "Умный 🇳🇱->🇷🇺".to_string(),
|
||||
server_type: "vless".to_string(),
|
||||
server: "media.example.test".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user