Fix unit tests
This commit is contained in:
parent
168a90dfb5
commit
7ee11f0eb6
2 changed files with 44 additions and 12 deletions
|
@ -287,20 +287,20 @@ fn parse_create_bucket_xml(xml_bytes: &[u8]) -> Option<Option<String>> {
|
||||||
|
|
||||||
let xml = roxmltree::Document::parse(xml_str).ok()?;
|
let xml = roxmltree::Document::parse(xml_str).ok()?;
|
||||||
|
|
||||||
let root = xml.root();
|
let cbc = xml.root().first_child()?;
|
||||||
let cbc = root.first_child()?;
|
|
||||||
if !cbc.has_tag_name("CreateBucketConfiguration") {
|
if !cbc.has_tag_name("CreateBucketConfiguration") {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ret = None;
|
let mut ret = None;
|
||||||
for item in cbc.children() {
|
for item in cbc.children() {
|
||||||
|
println!("{:?}", item);
|
||||||
if item.has_tag_name("LocationConstraint") {
|
if item.has_tag_name("LocationConstraint") {
|
||||||
if ret != None {
|
if ret != None {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
ret = Some(item.text()?.to_string());
|
ret = Some(item.text()?.to_string());
|
||||||
} else {
|
} else if !item.is_text() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,17 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[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/">
|
||||||
|
</CreateBucketConfiguration >
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
Some(None)
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_create_bucket_xml(
|
parse_create_bucket_xml(
|
||||||
br#"
|
br#"
|
||||||
|
@ -322,13 +332,13 @@ mod tests {
|
||||||
</CreateBucketConfiguration >
|
</CreateBucketConfiguration >
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
Some("Europe")
|
Some(Some("Europe".into()))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_create_bucket_xml(
|
parse_create_bucket_xml(
|
||||||
br#"
|
br#"
|
||||||
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
</CreateBucketConfiguration >
|
</Crea >
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
None
|
None
|
||||||
|
|
|
@ -1000,13 +1000,13 @@ mod tests {
|
||||||
$(
|
$(
|
||||||
assert!(
|
assert!(
|
||||||
matches!(
|
matches!(
|
||||||
parse(stringify!($method), $uri, Some("my_bucket".to_owned()), None),
|
parse(test_cases!{@actual_method $method}, $uri, Some("my_bucket".to_owned()), None),
|
||||||
Endpoint::$variant { .. }
|
Endpoint::$variant { .. }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
matches!(
|
matches!(
|
||||||
parse(stringify!($method), concat!("/my_bucket", $uri), None, None),
|
parse(test_cases!{@actual_method $method}, concat!("/my_bucket", $uri), None, None),
|
||||||
Endpoint::$variant { .. }
|
Endpoint::$variant { .. }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -1014,6 +1014,16 @@ mod tests {
|
||||||
test_cases!{@auth $method $uri}
|
test_cases!{@auth $method $uri}
|
||||||
)*
|
)*
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
(@actual_method HEAD) => {{ "HEAD" }};
|
||||||
|
(@actual_method GET) => {{ "GET" }};
|
||||||
|
(@actual_method OWNER_GET) => {{ "GET" }};
|
||||||
|
(@actual_method PUT) => {{ "PUT" }};
|
||||||
|
(@actual_method OWNER_PUT) => {{ "PUT" }};
|
||||||
|
(@actual_method POST) => {{ "POST" }};
|
||||||
|
(@actual_method DELETE) => {{ "DELETE" }};
|
||||||
|
(@actual_method OWNER_DELETE) => {{ "DELETE" }};
|
||||||
|
|
||||||
(@auth HEAD $uri:expr) => {{
|
(@auth HEAD $uri:expr) => {{
|
||||||
assert_eq!(parse("HEAD", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
assert_eq!(parse("HEAD", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
||||||
Authorization::Read("my_bucket"))
|
Authorization::Read("my_bucket"))
|
||||||
|
@ -1022,10 +1032,18 @@ mod tests {
|
||||||
assert_eq!(parse("GET", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
assert_eq!(parse("GET", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
||||||
Authorization::Read("my_bucket"))
|
Authorization::Read("my_bucket"))
|
||||||
}};
|
}};
|
||||||
|
(@auth OWNER_GET $uri:expr) => {{
|
||||||
|
assert_eq!(parse("GET", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
||||||
|
Authorization::Owner("my_bucket"))
|
||||||
|
}};
|
||||||
(@auth PUT $uri:expr) => {{
|
(@auth PUT $uri:expr) => {{
|
||||||
assert_eq!(parse("PUT", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
assert_eq!(parse("PUT", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
||||||
Authorization::Write("my_bucket"))
|
Authorization::Write("my_bucket"))
|
||||||
}};
|
}};
|
||||||
|
(@auth OWNER_PUT $uri:expr) => {{
|
||||||
|
assert_eq!(parse("PUT", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
||||||
|
Authorization::Owner("my_bucket"))
|
||||||
|
}};
|
||||||
(@auth POST $uri:expr) => {{
|
(@auth POST $uri:expr) => {{
|
||||||
assert_eq!(parse("POST", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
assert_eq!(parse("POST", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
||||||
Authorization::Write("my_bucket"))
|
Authorization::Write("my_bucket"))
|
||||||
|
@ -1034,6 +1052,10 @@ mod tests {
|
||||||
assert_eq!(parse("DELETE", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
assert_eq!(parse("DELETE", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
||||||
Authorization::Write("my_bucket"))
|
Authorization::Write("my_bucket"))
|
||||||
}};
|
}};
|
||||||
|
(@auth OWNER_DELETE $uri:expr) => {{
|
||||||
|
assert_eq!(parse("DELETE", concat!("/my_bucket", $uri), None, None).authorization_type(),
|
||||||
|
Authorization::Owner("my_bucket"))
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1109,7 +1131,7 @@ mod tests {
|
||||||
PUT "/" => CreateBucket
|
PUT "/" => CreateBucket
|
||||||
POST "/example-object?uploads" => CreateMultipartUpload
|
POST "/example-object?uploads" => CreateMultipartUpload
|
||||||
POST "/{Key+}?uploads" => CreateMultipartUpload
|
POST "/{Key+}?uploads" => CreateMultipartUpload
|
||||||
DELETE "/" => DeleteBucket
|
OWNER_DELETE "/" => DeleteBucket
|
||||||
DELETE "/?analytics&id=list1" => DeleteBucketAnalyticsConfiguration
|
DELETE "/?analytics&id=list1" => DeleteBucketAnalyticsConfiguration
|
||||||
DELETE "/?analytics&id=Id" => DeleteBucketAnalyticsConfiguration
|
DELETE "/?analytics&id=Id" => DeleteBucketAnalyticsConfiguration
|
||||||
DELETE "/?cors" => DeleteBucketCors
|
DELETE "/?cors" => DeleteBucketCors
|
||||||
|
@ -1124,7 +1146,7 @@ mod tests {
|
||||||
DELETE "/?policy" => DeleteBucketPolicy
|
DELETE "/?policy" => DeleteBucketPolicy
|
||||||
DELETE "/?replication" => DeleteBucketReplication
|
DELETE "/?replication" => DeleteBucketReplication
|
||||||
DELETE "/?tagging" => DeleteBucketTagging
|
DELETE "/?tagging" => DeleteBucketTagging
|
||||||
DELETE "/?website" => DeleteBucketWebsite
|
OWNER_DELETE "/?website" => DeleteBucketWebsite
|
||||||
DELETE "/my-second-image.jpg" => DeleteObject
|
DELETE "/my-second-image.jpg" => DeleteObject
|
||||||
DELETE "/my-third-image.jpg?versionId=UIORUnfndfiufdisojhr398493jfdkjFJjkndnqUifhnw89493jJFJ" => DeleteObject
|
DELETE "/my-third-image.jpg?versionId=UIORUnfndfiufdisojhr398493jfdkjFJjkndnqUifhnw89493jJFJ" => DeleteObject
|
||||||
DELETE "/Key+?versionId=VersionId" => DeleteObject
|
DELETE "/Key+?versionId=VersionId" => DeleteObject
|
||||||
|
@ -1153,7 +1175,7 @@ mod tests {
|
||||||
GET "/?requestPayment" => GetBucketRequestPayment
|
GET "/?requestPayment" => GetBucketRequestPayment
|
||||||
GET "/?tagging" => GetBucketTagging
|
GET "/?tagging" => GetBucketTagging
|
||||||
GET "/?versioning" => GetBucketVersioning
|
GET "/?versioning" => GetBucketVersioning
|
||||||
GET "/?website" => GetBucketWebsite
|
OWNER_GET "/?website" => GetBucketWebsite
|
||||||
GET "/my-image.jpg" => GetObject
|
GET "/my-image.jpg" => GetObject
|
||||||
GET "/myObject?versionId=3/L4kqtJlcpXroDTDmpUMLUo" => GetObject
|
GET "/myObject?versionId=3/L4kqtJlcpXroDTDmpUMLUo" => GetObject
|
||||||
GET "/Junk3.txt?response-cache-control=No-cache&response-content-disposition=attachment%3B%20filename%3Dtesting.txt&response-content-encoding=x-gzip&response-content-language=mi%2C%20en&response-expires=Thu%2C%2001%20Dec%201994%2016:00:00%20GMT" => GetObject
|
GET "/Junk3.txt?response-cache-control=No-cache&response-content-disposition=attachment%3B%20filename%3Dtesting.txt&response-content-encoding=x-gzip&response-content-language=mi%2C%20en&response-expires=Thu%2C%2001%20Dec%201994%2016:00:00%20GMT" => GetObject
|
||||||
|
@ -1227,7 +1249,7 @@ mod tests {
|
||||||
PUT "/?requestPayment" => PutBucketRequestPayment
|
PUT "/?requestPayment" => PutBucketRequestPayment
|
||||||
PUT "/?tagging" => PutBucketTagging
|
PUT "/?tagging" => PutBucketTagging
|
||||||
PUT "/?versioning" => PutBucketVersioning
|
PUT "/?versioning" => PutBucketVersioning
|
||||||
PUT "/?website" => PutBucketWebsite
|
OWNER_PUT "/?website" => PutBucketWebsite
|
||||||
PUT "/my-image.jpg" => PutObject
|
PUT "/my-image.jpg" => PutObject
|
||||||
PUT "/Key+" => PutObject
|
PUT "/Key+" => PutObject
|
||||||
PUT "/my-image.jpg?acl" => PutObjectAcl
|
PUT "/my-image.jpg?acl" => PutObjectAcl
|
||||||
|
|
Loading…
Reference in a new issue