Skip to content

Commit 171c51d

Browse files
AzrenbethAzrenbeth
Azrenbeth
authored and
Azrenbeth
committed
Wrote tests for config::new() which is used by pyo3 code
1 parent d9c474e commit 171c51d

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

src/lib.rs

+90
Original file line numberDiff line numberDiff line change
@@ -1032,3 +1032,93 @@ mod lib_tests {
10321032

10331033
//TODO: tests for correct SQL code produced by output_sql
10341034
}
1035+
1036+
#[cfg(test)]
1037+
mod pyo3_tests {
1038+
use crate::{Config, LevelSizes};
1039+
1040+
#[test]
1041+
fn new_config_correct_when_things_empty() {
1042+
let db_url = "postresql://homeserver.com/synapse".to_string();
1043+
let room_id = "[email protected]".to_string();
1044+
let output_file = None;
1045+
let min_state_group = None;
1046+
let groups_to_compress = None;
1047+
let min_saved_rows = None;
1048+
let max_state_group = None;
1049+
let level_sizes = "100,50,25".to_string();
1050+
let transactions = false;
1051+
let graphs = false;
1052+
1053+
let config = Config::new(
1054+
db_url.clone(),
1055+
room_id.clone(),
1056+
output_file,
1057+
min_state_group,
1058+
groups_to_compress,
1059+
min_saved_rows,
1060+
max_state_group,
1061+
level_sizes,
1062+
transactions,
1063+
graphs,
1064+
)
1065+
.unwrap();
1066+
1067+
assert_eq!(config.db_url, db_url);
1068+
assert!(config.output_file.is_none());
1069+
assert_eq!(config.room_id, room_id);
1070+
assert!(config.min_state_group.is_none());
1071+
assert!(config.groups_to_compress.is_none());
1072+
assert!(config.min_saved_rows.is_none());
1073+
assert!(config.max_state_group.is_none());
1074+
assert_eq!(
1075+
config.level_sizes,
1076+
"100,50,25".parse::<LevelSizes>().unwrap()
1077+
);
1078+
assert_eq!(config.transactions, transactions);
1079+
assert_eq!(config.graphs, graphs);
1080+
}
1081+
1082+
#[test]
1083+
fn new_config_correct_when_things_not_empty() {
1084+
// db_url and room_id have to be set or it will panic
1085+
let db_url = "postresql://homeserver.com/synapse".to_string();
1086+
let room_id = "room_id".to_string();
1087+
let output_file = Some("/tmp/myFile".to_string());
1088+
let min_state_group = Some(3225);
1089+
let groups_to_compress = Some(970);
1090+
let min_saved_rows = Some(500);
1091+
let max_state_group = Some(3453);
1092+
let level_sizes = "128,64,32".to_string();
1093+
let transactions = true;
1094+
let graphs = true;
1095+
1096+
let config = Config::new(
1097+
db_url.clone(),
1098+
room_id.clone(),
1099+
output_file,
1100+
min_state_group,
1101+
groups_to_compress,
1102+
min_saved_rows,
1103+
max_state_group,
1104+
level_sizes,
1105+
transactions,
1106+
graphs,
1107+
)
1108+
.unwrap();
1109+
1110+
assert_eq!(config.db_url, db_url);
1111+
assert!(!config.output_file.is_none());
1112+
assert_eq!(config.room_id, room_id);
1113+
assert_eq!(config.min_state_group, Some(3225));
1114+
assert_eq!(config.groups_to_compress, Some(970));
1115+
assert_eq!(config.min_saved_rows, Some(500));
1116+
assert_eq!(config.max_state_group, Some(3453));
1117+
assert_eq!(
1118+
config.level_sizes,
1119+
"128,64,32".parse::<LevelSizes>().unwrap()
1120+
);
1121+
assert_eq!(config.transactions, transactions);
1122+
assert_eq!(config.graphs, graphs);
1123+
}
1124+
}

0 commit comments

Comments
 (0)