@@ -182,16 +182,28 @@ mod tests {
182
182
assert_eq ! ( "http/1.1" . as_bytes( ) , & alpn[ 1 ] ) ;
183
183
}
184
184
185
+ fn unwrap_err_create_server_config ( cert : & Cert ) -> String {
186
+ match create_server_config ( & cert) {
187
+ Err ( e) => format ! ( "{}" , e) ,
188
+ _ => unreachable ! ( ) ,
189
+ }
190
+ }
191
+
192
+ // useless but 100% coverage is still nice
193
+ #[ test]
194
+ #[ should_panic]
195
+ fn panic_unwrap_create_server_config_error ( ) {
196
+ let cert = create_cert ( ) ;
197
+ unwrap_err_create_server_config ( & cert) ;
198
+ }
199
+
185
200
#[ test]
186
201
fn test_empty_cert ( ) {
187
202
let mut cert = create_cert ( ) ;
188
203
cert. cert = None ;
189
204
cert. private = None ;
190
205
191
- let error = match create_server_config ( & cert) {
192
- Err ( e) => format ! ( "{}" , e) ,
193
- _ => unreachable ! ( ) ,
194
- } ;
206
+ let error = unwrap_err_create_server_config ( & cert) ;
195
207
assert ! ( error. contains( & format!( "{:?}" , cert) ) ) ;
196
208
assert ! ( error. contains( "has no Cert or Private" ) ) ;
197
209
}
@@ -201,22 +213,21 @@ mod tests {
201
213
let mut cert = create_cert ( ) ;
202
214
* cert. private . as_mut ( ) . unwrap ( ) = "WRONG" . to_owned ( ) ;
203
215
204
- let error = match create_server_config ( & cert) {
205
- Err ( e) => format ! ( "{}" , e) ,
206
- _ => unreachable ! ( ) ,
207
- } ;
208
- // unclear why the error gets no triggered earlier
216
+ let error = unwrap_err_create_server_config ( & cert) ;
217
+
218
+ // todo: investigate
219
+ // unclear why the error gets not triggered earlier
209
220
assert ! ( error. contains( "Private Vec is empty" ) ) ;
210
221
}
211
222
212
- // todo: fix
213
- fn _test_invalid_cert ( ) {
223
+ #[ test]
224
+ #[ should_panic]
225
+ // todo: rustls does no cert validation so this test panics
226
+ fn test_invalid_cert ( ) {
214
227
let mut cert = create_cert ( ) ;
215
228
* cert. cert . as_mut ( ) . unwrap ( ) = "WRONG" . to_owned ( ) ;
216
229
217
- let _error = match create_server_config ( & cert) {
218
- Err ( e) => format ! ( "{}" , e) ,
219
- _ => unreachable ! ( ) ,
220
- } ;
230
+ let error = unwrap_err_create_server_config ( & cert) ;
231
+ assert ! ( error. contains( "Cert is invalid" ) ) ;
221
232
}
222
233
}
0 commit comments