diff options
author | Alex Auvolat <alex@adnab.me> | 2022-01-05 17:34:48 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-01-05 17:34:48 +0100 |
commit | 7ee11f0eb6327ea809b7ca27cfdf0b1d70cdbde9 (patch) | |
tree | 5266f38e047ef2d089d65d1047588ec885da291a /src/api/s3_bucket.rs | |
parent | 168a90dfb5489d465d64f066f375e5d06bc1f08c (diff) | |
download | garage-7ee11f0eb6327ea809b7ca27cfdf0b1d70cdbde9.tar.gz garage-7ee11f0eb6327ea809b7ca27cfdf0b1d70cdbde9.zip |
Fix unit tests
Diffstat (limited to 'src/api/s3_bucket.rs')
-rw-r--r-- | src/api/s3_bucket.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/api/s3_bucket.rs b/src/api/s3_bucket.rs index fb3e982d..3766bf86 100644 --- a/src/api/s3_bucket.rs +++ b/src/api/s3_bucket.rs @@ -287,20 +287,20 @@ fn parse_create_bucket_xml(xml_bytes: &[u8]) -> Option<Option<String>> { let xml = roxmltree::Document::parse(xml_str).ok()?; - let root = xml.root(); - let cbc = root.first_child()?; + let cbc = xml.root().first_child()?; if !cbc.has_tag_name("CreateBucketConfiguration") { return None; } let mut ret = None; for item in cbc.children() { + println!("{:?}", item); if item.has_tag_name("LocationConstraint") { if ret != None { return None; } ret = Some(item.text()?.to_string()); - } else { + } else if !item.is_text() { return None; } } @@ -313,24 +313,34 @@ mod tests { use super::*; #[test] - fn create_bucket() -> Result<(), ()> { + fn create_bucket() { + assert_eq!(parse_create_bucket_xml(br#""#), Some(None)); assert_eq!( parse_create_bucket_xml( br#" <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> - <LocationConstraint>Europe</LocationConstraint> </CreateBucketConfiguration > "# ), - Some("Europe") + Some(None) ); assert_eq!( parse_create_bucket_xml( br#" <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> + <LocationConstraint>Europe</LocationConstraint> </CreateBucketConfiguration > "# ), + Some(Some("Europe".into())) + ); + assert_eq!( + parse_create_bucket_xml( + br#" + <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> + </Crea > + "# + ), None ); } |