extern crate dono; extern crate rustc_serialize; use self::rustc_serialize::json; use dono::*; #[test] fn dono_error_can_be_json_encoded_and_decoded() { let error = DonoError { code: "TS000".to_string(), field: "test".to_string(), message: "Test".to_string(), description: "Extended test".to_string() }; let encoded = json::encode(&error).unwrap(); let expected = "{\"field\":\"test\",\"code\":\"TS000\",\ \"description\":\"Extended test\",\"message\":\"Test\"}"; assert_eq!(expected, encoded); let decoded: DonoError = json::decode(&encoded).unwrap(); assert_eq!(error, decoded); } #[test] fn it_computes_a_password() { let dono = Dono::new(); let key = "helloworldofpasswo".to_string(); let label = "rds".to_string(); let password = dono.compute_password(&key, &label); let password = password.unwrap(); let expected = "xU+T8Pk5OjxrWquYTzNjJkqzPqR/NQ+xuJrOelQZ8yE="; assert_eq!(expected, password); } #[test] fn it_returns_an_error_if_the_key_is_too_short() { let dono = Dono::new(); let key = "helloworl".to_string(); let label = "rds".to_string(); let password = dono.compute_password(&key, &label); let password = password; assert!(password.is_err()); let error = password.unwrap_err(); assert_eq!("CP001", error.code); }