diff options
| author | David Lönnhager <david.l@mullvad.net> | 2022-04-04 14:47:13 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-04-04 15:03:52 +0200 |
| commit | 75bc67348b6d94a9c0bfbd2bfa2ca305bb543aec (patch) | |
| tree | 917b905e83984902f1f01ad24156e862d4856f16 /mullvad-daemon/src | |
| parent | cdc33a27d5b30a23ca4b1fffe7ab19dccad966ed (diff) | |
| download | mullvadvpn-75bc67348b6d94a9c0bfbd2bfa2ca305bb543aec.tar.xz mullvadvpn-75bc67348b6d94a9c0bfbd2bfa2ca305bb543aec.zip | |
Add unit test for empty account history
Diffstat (limited to 'mullvad-daemon/src')
| -rw-r--r-- | mullvad-daemon/src/migrations/account_history.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/mullvad-daemon/src/migrations/account_history.rs b/mullvad-daemon/src/migrations/account_history.rs index 54f07b8b32..06a8326f04 100644 --- a/mullvad-daemon/src/migrations/account_history.rs +++ b/mullvad-daemon/src/migrations/account_history.rs @@ -138,6 +138,11 @@ mod test { "accounts": ["1234", "4567"] } "#; + pub const ACCOUNT_HISTORY_V1_EMPTY: &str = r#" +{ + "accounts": [] +} +"#; pub const ACCOUNT_HISTORY_V2: &str = r#" [ { @@ -163,6 +168,7 @@ mod test { } } ]"#; + pub const ACCOUNT_HISTORY_V2_EMPTY: &str = r#"[]"#; pub const ACCOUNT_HISTORY_V3: &str = r#"123456"#; pub const OLD_SETTINGS: &str = r#" @@ -331,7 +337,7 @@ mod test { #[test] fn test_v2() { - assert!(super::try_format_v2(ACCOUNT_HISTORY_V1.as_bytes()).is_none()); + assert!(super::try_format_v2(ACCOUNT_HISTORY_V1.as_bytes()).is_err()); let mut old_settings = serde_json::from_str(OLD_SETTINGS).unwrap(); let new_settings: serde_json::Value = serde_json::from_str(NEW_SETTINGS).unwrap(); @@ -341,12 +347,22 @@ mod test { super::migrate_formats_inner(ACCOUNT_HISTORY_V2.as_bytes(), &mut old_settings).unwrap(); assert_eq!(&old_settings, &new_settings); - assert_eq!(token, "1234"); + assert_eq!(token, Some("1234".to_string())); + + // Test whether empty histories are handled correctly + let mut old_settings = serde_json::from_str(OLD_SETTINGS).unwrap(); + let token = + super::migrate_formats_inner(ACCOUNT_HISTORY_V2_EMPTY.as_bytes(), &mut old_settings) + .unwrap(); + assert_eq!(&old_settings, &old_settings); + assert_eq!(token, None); } #[test] fn test_v1() { - let token = super::try_format_v1(ACCOUNT_HISTORY_V1.as_bytes()); + let token = super::try_format_v1(ACCOUNT_HISTORY_V1.as_bytes()).unwrap(); assert_eq!(token, Some("1234".to_string())); + let token = super::try_format_v1(ACCOUNT_HISTORY_V1_EMPTY.as_bytes()).unwrap(); + assert_eq!(token, None); } } |
