@@ -124,41 +124,50 @@ impl From<PoisonError<MutexGuard<'_, HashMap<std::string::String, KvsValue>>>> f
124124}
125125
126126#[ cfg( test) ]
127- mod tests {
128- use super :: * ;
127+ mod error_code_tests {
128+ use crate :: error_code:: ErrorCode ;
129+ use crate :: kvs_value:: KvsValue ;
130+ use std:: collections:: HashMap ;
131+ use std:: io:: { Error , ErrorKind } ;
129132 use std:: sync:: { Arc , Mutex } ;
130133 use std:: thread;
131134
132135 #[ test]
133- fn test_unknown_error_code_from_io_error ( ) {
136+ fn test_from_io_error_to_file_not_found ( ) {
137+ let error = Error :: new ( ErrorKind :: NotFound , "File not found" ) ;
138+ assert_eq ! ( ErrorCode :: from( error) , ErrorCode :: FileNotFound ) ;
139+ }
140+
141+ #[ test]
142+ fn test_from_io_error_to_unmapped_error ( ) {
134143 let error = std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidInput , "Invalid input provided" ) ;
135144 assert_eq ! ( ErrorCode :: from( error) , ErrorCode :: UnmappedError ) ;
136145 }
137146
138147 #[ test]
139- fn test_conversion_failed_from_utf8_error ( ) {
148+ fn test_from_utf8_error_to_conversion_failed ( ) {
140149 // test from: https://doc.rust-lang.org/std/string/struct.FromUtf8Error.html
141150 let bytes = vec ! [ 0 , 159 ] ;
142151 let error = String :: from_utf8 ( bytes) . unwrap_err ( ) ;
143152 assert_eq ! ( ErrorCode :: from( error) , ErrorCode :: ConversionFailed ) ;
144153 }
145154
146155 #[ test]
147- fn test_conversion_failed_from_slice_error ( ) {
156+ fn test_from_try_from_slice_error_to_conversion_failed ( ) {
148157 let bytes = [ 0x12 , 0x34 , 0x56 , 0x78 , 0xab ] ;
149158 let bytes_ptr: & [ u8 ] = & bytes;
150159 let error = TryInto :: < [ u8 ; 8 ] > :: try_into ( bytes_ptr) . unwrap_err ( ) ;
151160 assert_eq ! ( ErrorCode :: from( error) , ErrorCode :: ConversionFailed ) ;
152161 }
153162
154163 #[ test]
155- fn test_conversion_failed_from_vec_u8 ( ) {
164+ fn test_from_vec8_to_conversion_failed ( ) {
156165 let bytes: Vec < u8 > = vec ! [ ] ;
157166 assert_eq ! ( ErrorCode :: from( bytes) , ErrorCode :: ConversionFailed ) ;
158167 }
159168
160169 #[ test]
161- fn test_mutex_lock_failed_from_poison_error ( ) {
170+ fn test_from_poison_error_mutex_lock_failed ( ) {
162171 let mutex: Arc < Mutex < HashMap < String , KvsValue > > > = Arc :: default ( ) ;
163172
164173 // test from: https://doc.rust-lang.org/std/sync/struct.PoisonError.html
0 commit comments