@@ -70,3 +70,64 @@ impl From<anyhow::Error> for ArchiveError {
7070 ArchiveError :: Unexpected ( error. to_string ( ) )
7171 }
7272}
73+
74+ /// These are relatively low value tests; they are here to reduce the coverage gap and
75+ /// ensure that the error conversions are working as expected.
76+ #[ cfg( test) ]
77+ mod test {
78+ use super :: * ;
79+ use std:: path:: PathBuf ;
80+ use std:: str:: FromStr ;
81+
82+ #[ test]
83+ fn test_from_regex_error ( ) {
84+ let regex_error = regex:: Error :: Syntax ( "test" . to_string ( ) ) ;
85+ let error = ArchiveError :: from ( regex_error) ;
86+ assert_eq ! ( error. to_string( ) , "test" ) ;
87+ }
88+
89+ #[ tokio:: test]
90+ async fn test_from_reqwest_error ( ) {
91+ let result = reqwest:: get ( "https://a.com" ) . await ;
92+ assert ! ( result. is_err( ) ) ;
93+ if let Err ( error) = result {
94+ let error = ArchiveError :: from ( error) ;
95+ assert ! ( error. to_string( ) . contains( "https://a.com" ) ) ;
96+ }
97+ }
98+
99+ #[ test]
100+ fn test_from_io_error ( ) {
101+ let io_error = std:: io:: Error :: new ( std:: io:: ErrorKind :: NotFound , "test" ) ;
102+ let error = ArchiveError :: from ( io_error) ;
103+ assert_eq ! ( error. to_string( ) , "test" ) ;
104+ }
105+
106+ #[ test]
107+ fn test_from_parse_int_error ( ) {
108+ let result = u64:: from_str ( "test" ) ;
109+ assert ! ( result. is_err( ) ) ;
110+ if let Err ( error) = result {
111+ let error = ArchiveError :: from ( error) ;
112+ assert_eq ! ( error. to_string( ) , "invalid digit found in string" ) ;
113+ }
114+ }
115+
116+ #[ test]
117+ fn test_from_strip_prefix_error ( ) {
118+ let path = PathBuf :: from ( "test" ) ;
119+ let result = path. strip_prefix ( "foo" ) ;
120+ assert ! ( result. is_err( ) ) ;
121+ if let Err ( error) = result {
122+ let error = ArchiveError :: from ( error) ;
123+ assert_eq ! ( error. to_string( ) , "prefix not found" ) ;
124+ }
125+ }
126+
127+ #[ test]
128+ fn test_from_anyhow_error ( ) {
129+ let anyhow_error = anyhow:: Error :: msg ( "test" ) ;
130+ let error = ArchiveError :: from ( anyhow_error) ;
131+ assert_eq ! ( error. to_string( ) , "test" ) ;
132+ }
133+ }
0 commit comments