@@ -1018,3 +1018,138 @@ mod lib_tests {
1018
1018
1019
1019
//TODO: tests for correct SQL code produced by output_sql
1020
1020
}
1021
+
1022
+ #[ cfg( test) ]
1023
+ mod pyo3_tests {
1024
+ use crate :: { Config , LevelSizes } ;
1025
+
1026
+ #[ test]
1027
+ #[ should_panic]
1028
+ fn new_config_panics_if_no_db_url ( ) {
1029
+ let db_url = "" . to_string ( ) ;
1030
+ let output_file = "" . to_string ( ) ;
1031
+ let room_id =
"[email protected] " . to_string ( ) ;
1032
+ let min_state_group = "" . to_string ( ) ;
1033
+ let groups_to_compress = "" . to_string ( ) ;
1034
+ let min_saved_rows = "" . to_string ( ) ;
1035
+ let level_sizes = "" . to_string ( ) ;
1036
+ let transactions = false ;
1037
+ let graphs = false ;
1038
+
1039
+ Config :: new (
1040
+ db_url,
1041
+ output_file,
1042
+ room_id,
1043
+ min_state_group,
1044
+ groups_to_compress,
1045
+ min_saved_rows,
1046
+ level_sizes,
1047
+ transactions,
1048
+ graphs,
1049
+ ) ;
1050
+ }
1051
+
1052
+ #[ test]
1053
+ #[ should_panic]
1054
+ fn new_config_panics_if_no_room_id ( ) {
1055
+ let db_url = "postresql://homeserver.com/synapse" . to_string ( ) ;
1056
+ let output_file = "" . to_string ( ) ;
1057
+ let room_id = "" . to_string ( ) ;
1058
+ let min_state_group = "" . to_string ( ) ;
1059
+ let groups_to_compress = "" . to_string ( ) ;
1060
+ let min_saved_rows = "" . to_string ( ) ;
1061
+ let level_sizes = "" . to_string ( ) ;
1062
+ let transactions = false ;
1063
+ let graphs = false ;
1064
+
1065
+ Config :: new (
1066
+ db_url,
1067
+ output_file,
1068
+ room_id,
1069
+ min_state_group,
1070
+ groups_to_compress,
1071
+ min_saved_rows,
1072
+ level_sizes,
1073
+ transactions,
1074
+ graphs,
1075
+ ) ;
1076
+ }
1077
+
1078
+ #[ test]
1079
+ fn new_config_correct_when_things_empty ( ) {
1080
+ // db_url and room_id have to be set or it will panic
1081
+ let db_url = "postresql://homeserver.com/synapse" . to_string ( ) ;
1082
+ let output_file = "" . to_string ( ) ;
1083
+ let room_id = "room_id" . to_string ( ) ;
1084
+ let min_state_group = "" . to_string ( ) ;
1085
+ let groups_to_compress = "" . to_string ( ) ;
1086
+ let min_saved_rows = "" . to_string ( ) ;
1087
+ let level_sizes = "" . to_string ( ) ;
1088
+ let transactions = false ;
1089
+ let graphs = false ;
1090
+
1091
+ let config = Config :: new (
1092
+ db_url. clone ( ) ,
1093
+ output_file,
1094
+ room_id. clone ( ) ,
1095
+ min_state_group,
1096
+ groups_to_compress,
1097
+ min_saved_rows,
1098
+ level_sizes,
1099
+ transactions,
1100
+ graphs,
1101
+ ) ;
1102
+
1103
+ assert_eq ! ( config. db_url, db_url) ;
1104
+ assert ! ( config. output_file. is_none( ) ) ;
1105
+ assert_eq ! ( config. room_id, room_id) ;
1106
+ assert ! ( config. min_state_group. is_none( ) ) ;
1107
+ assert ! ( config. groups_to_compress. is_none( ) ) ;
1108
+ assert ! ( config. min_saved_rows. is_none( ) ) ;
1109
+ assert_eq ! (
1110
+ config. level_sizes,
1111
+ "100,50,25" . parse:: <LevelSizes >( ) . unwrap( )
1112
+ ) ;
1113
+ assert_eq ! ( config. transactions, transactions) ;
1114
+ assert_eq ! ( config. graphs, graphs) ;
1115
+ }
1116
+
1117
+ #[ test]
1118
+ fn new_config_correct_when_things_not_empty ( ) {
1119
+ // db_url and room_id have to be set or it will panic
1120
+ let db_url = "postresql://homeserver.com/synapse" . to_string ( ) ;
1121
+ let output_file = "/tmp/myFile" . to_string ( ) ;
1122
+ let room_id = "room_id" . to_string ( ) ;
1123
+ let min_state_group = "3225" . to_string ( ) ;
1124
+ let groups_to_compress = "970" . to_string ( ) ;
1125
+ let min_saved_rows = "500" . to_string ( ) ;
1126
+ let level_sizes = "128,64,32" . to_string ( ) ;
1127
+ let transactions = true ;
1128
+ let graphs = true ;
1129
+
1130
+ let config = Config :: new (
1131
+ db_url. clone ( ) ,
1132
+ output_file,
1133
+ room_id. clone ( ) ,
1134
+ min_state_group,
1135
+ groups_to_compress,
1136
+ min_saved_rows,
1137
+ level_sizes,
1138
+ transactions,
1139
+ graphs,
1140
+ ) ;
1141
+
1142
+ assert_eq ! ( config. db_url, db_url) ;
1143
+ assert ! ( !config. output_file. is_none( ) ) ;
1144
+ assert_eq ! ( config. room_id, room_id) ;
1145
+ assert_eq ! ( config. min_state_group, Some ( 3225 ) ) ;
1146
+ assert_eq ! ( config. groups_to_compress, Some ( 970 ) ) ;
1147
+ assert_eq ! ( config. min_saved_rows, Some ( 500 ) ) ;
1148
+ assert_eq ! (
1149
+ config. level_sizes,
1150
+ "128,64,32" . parse:: <LevelSizes >( ) . unwrap( )
1151
+ ) ;
1152
+ assert_eq ! ( config. transactions, transactions) ;
1153
+ assert_eq ! ( config. graphs, graphs) ;
1154
+ }
1155
+ }
0 commit comments