Unverified Commit 5719acda authored by Nugine's avatar Nugine
Browse files

s3s: xml: move tests

parent 0b4da89b
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -49,5 +49,4 @@ transform-stream = "0.3.0"
urlencoding = "2.1.2"

[dev-dependencies]
const-str = "0.5.3"
tokio = { version = "1.25.0", features = ["full"] }
+1 −3
Original line number Diff line number Diff line
@@ -7,6 +7,4 @@ pub use self::ser::*;
mod generated;

#[cfg(test)]
mod tests {
    mod de;
}
mod tests;
+148 −0
Original line number Diff line number Diff line
use crate::xml;

use const_str::concat;

const DATA_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/src/xml/tests");

fn read(path: &str) -> Vec<u8> {
    std::fs::read(path).unwrap()
}

fn deserialize<T>(input: &[u8]) -> xml::DeResult<T>
where
    T: for<'xml> xml::Deserialize<'xml>,
@@ -18,11 +10,36 @@ where
    Ok(ans)
}

fn serialize_content<T: xml::SerializeContent>(val: &T) -> xml::SerResult<String> {
    let mut buf = Vec::with_capacity(256);
    {
        let mut ser = xml::Serializer::new(&mut buf);
        val.serialize_content(&mut ser)?;
    }
    Ok(String::from_utf8(buf).unwrap())
}

/// See <https://github.com/Nugine/s3s/issues/2>
#[test]
fn d001() {
    let input = read(concat!(DATA_DIR, "/d001.xml"));
    let ans = deserialize::<crate::dto::CompletedMultipartUpload>(&input).unwrap();
    let input = r#"
        <CompleteMultipartUpload>
            <Part>
                <PartNumber>1</PartNumber>
                <ETag>"a54357aff0632cce46d942af68356b38"</ETag>
            </Part>
            <Part>
                <PartNumber>2</PartNumber>
                <ETag>"0c78aef83f66abc1fa1e8477f296d394"</ETag>
            </Part>
            <Part>
                <PartNumber>3</PartNumber>
                <ETag>"acbd18db4cc2f85cedef654fccc4a4d8"</ETag>
            </Part>
        </CompleteMultipartUpload>
    "#;

    let ans = deserialize::<crate::dto::CompletedMultipartUpload>(input.as_bytes()).unwrap();

    let parts = ans.parts.as_deref().unwrap();
    assert_eq!(parts.len(), 3);
@@ -39,8 +56,31 @@ fn d001() {

#[test]
fn d002() {
    let input = read(concat!(DATA_DIR, "/d002.xml"));
    let ans = deserialize::<crate::dto::SelectObjectContentRequest>(&input).unwrap();
    let input = r#"
        <SelectObjectContentRequest xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
            <Expression>select * from s3object</Expression>
            <ExpressionType>SQL</ExpressionType>
            <InputSerialization>
                <CompressionType>NONE</CompressionType>
                <CSV>
                    <AllowQuotedRecordDelimiter>FALSE</AllowQuotedRecordDelimiter>
                    <Comments>#</Comments>
                    <FieldDelimiter>,</FieldDelimiter>
                    <FileHeaderInfo>NONE</FileHeaderInfo>
                    <QuoteCharacter>""</QuoteCharacter>
                    <QuoteEscapeCharacter>"</QuoteEscapeCharacter>
                    <RecordDelimiter>\n</RecordDelimiter>
                </CSV>
            </InputSerialization>
            <OutputSerialization>
                <JSON>
                    <RecordDelimiter>\n</RecordDelimiter>
                </JSON>
            </OutputSerialization>
        </SelectObjectContentRequest>
    "#;

    let ans = deserialize::<crate::dto::SelectObjectContentRequest>(input.as_bytes()).unwrap();

    {
        let csv = ans.input_serialization.csv.as_ref().unwrap();
@@ -50,8 +90,18 @@ fn d002() {

#[test]
fn d003() {
    let input = read(concat!(DATA_DIR, "/d003.xml"));
    let ans = deserialize::<crate::dto::Tagging>(&input).unwrap();
    let input = r#"
        <Tagging xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
            <TagSet>
                <Tag>
                    <Key>Key4</Key>
                    <Value>Value4</Value>
                </Tag>
            </TagSet>
        </Tagging>
    "#;

    let ans = deserialize::<crate::dto::Tagging>(input.as_bytes()).unwrap();

    assert_eq!(ans.tag_set.len(), 1);
    let tag = &ans.tag_set[0];
@@ -61,9 +111,38 @@ fn d003() {

#[test]
fn d004() {
    let input = read(concat!(DATA_DIR, "/d004.xml"));
    let ans = deserialize::<crate::dto::SelectObjectContentRequest>(&input).unwrap();
    let input = r#"
        <SelectObjectContentRequest xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
            <Expression>select * from s3object</Expression>
            <ExpressionType>SQL</ExpressionType>
            <InputSerialization>
                <CSV />
            </InputSerialization>
            <OutputSerialization>
                <CSV />
            </OutputSerialization>
            <RequestProgress>
                <Enabled>true</Enabled>
            </RequestProgress>
        </SelectObjectContentRequest>
    "#;

    let ans = deserialize::<crate::dto::SelectObjectContentRequest>(input.as_bytes()).unwrap();

    assert!(ans.input_serialization.csv.is_some());
    assert!(ans.output_serialization.csv.is_some());
}

#[test]
fn s001() {
    let val = crate::dto::LifecycleExpiration {
        date: None,
        days: 365,
        expired_object_delete_marker: false,
    };

    let ans = serialize_content(&val).unwrap();
    let expected = "<Days>365</Days><ExpiredObjectDeleteMarker>false</ExpiredObjectDeleteMarker>";

    assert_eq!(ans, expected);
}

crates/s3s/src/xml/tests/d001.xml

deleted100644 → 0
+0 −15
Original line number Diff line number Diff line
<CompleteMultipartUpload>
    <Part>
        <PartNumber>1</PartNumber>
        <ETag>"a54357aff0632cce46d942af68356b38"</ETag>
    </Part>
    <Part>
        <PartNumber>2</PartNumber>
        <ETag>"0c78aef83f66abc1fa1e8477f296d394"</ETag>
    </Part>
    <Part>
        <PartNumber>3</PartNumber>
        <ETag>"acbd18db4cc2f85cedef654fccc4a4d8"</ETag>
    </Part>
</CompleteMultipartUpload>
    
 No newline at end of file

crates/s3s/src/xml/tests/d002.xml

deleted100644 → 0
+0 −21
Original line number Diff line number Diff line
<SelectObjectContentRequest xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <Expression>select * from s3object</Expression>
    <ExpressionType>SQL</ExpressionType>
    <InputSerialization>
        <CompressionType>NONE</CompressionType>
        <CSV>
            <AllowQuotedRecordDelimiter>FALSE</AllowQuotedRecordDelimiter>
            <Comments>#</Comments>
            <FieldDelimiter>,</FieldDelimiter>
            <FileHeaderInfo>NONE</FileHeaderInfo>
            <QuoteCharacter>""</QuoteCharacter>
            <QuoteEscapeCharacter>"</QuoteEscapeCharacter>
            <RecordDelimiter>\n</RecordDelimiter>
        </CSV>
    </InputSerialization>
    <OutputSerialization>
        <JSON>
            <RecordDelimiter>\n</RecordDelimiter>
        </JSON>
    </OutputSerialization>
</SelectObjectContentRequest>
 No newline at end of file
Loading