<commit_before>//! The AWS S3 API.

include!(concat!(env!("OUT_DIR"), "/s3.rs"));

#[cfg(test)]
mod test {
    use std::io::{Read, BufReader};
    use std::fs::File;
    use s3::{S3Client, HeadObjectRequest, GetObjectRequest, ListMultipartUploadsRequest};
    use s3::{CreateMultipartUploadOutputDeserializer, CompleteMultipartUploadOutputDeserializer};
    use s3::{ListMultipartUploadsOutputDeserializer, ListPartsRequest, Initiator, Owner};
    use xmlutil::{XmlResponse, Next};
    use xml::EventReader;

    use super::super::{Region, SignedRequest};
    use super::super::mock::*;

    extern crate env_logger;

    #[test]
    fn initiate_multipart_upload_happy_path() {
        let file = File::open("tests/sample-data/s3_initiate_multipart_upload.xml").unwrap();
        let mut file = BufReader::new(file);
        let mut raw = String::new();
        file.read_to_string(&mut raw).unwrap();
        let mut my_parser  = EventReader::from_str(&raw);
        let my_stack = my_parser.into_iter().peekable();
        let mut reader = XmlResponse::new(my_stack);
        reader.next(); // xml start node
        let result = CreateMultipartUploadOutputDeserializer::deserialize("InitiateMultipartUploadResult", &mut reader);

        match result {
            Err(_) => panic!("Couldn't parse initiate_multipart_upload"),
            Ok(result) => {
                assert_eq!(sstr("example-bucket"), result.bucket);
                assert_eq!(sstr("example-object"), result.key);
                assert_eq!(sstr("<KEY>"), result.upload_id);
            }
        }
    }

    #[test]
    fn complete_multipart_upload_happy_path() {
        let file = File::open("tests/sample-data/s3_complete_multipart_upload.xml").unwrap();
        let mut file = BufReader::new(file);
        let mut raw = String::new();
        file.read_to_string(&mut raw).unwrap();
        let mut my_parser  = EventReader::from_str(&raw);
        let my_stack = my_parser.into_iter().peekable();
        let mut reader = XmlResponse::new(my_stack);
        reader.next(); // xml start node
        let result = CompleteMultipartUploadOutputDeserializer::deserialize("CompleteMultipartUploadResult", &mut reader);

        match result {
            Err(_) => panic!("Couldn't parse s3_complete_multipart_upload"),
            Ok(result) => {
                assert_eq!(result.bucket, sstr("testbucket2"));
                assert_eq!(result.key, sstr("foo.zip"));
                assert_eq!(result.e_tag, sstr("\"525a81fcbc4181997bd96e4096fa7304-1\""));
            }
        }
    }

    #[test]
    fn list_multipart_upload_happy_path() {
        let file = File::open("tests/sample-data/s3_list_multipart_uploads.xml").unwrap();
        let mut file = BufReader::new(file);
        let mut raw = String::new();
        file.read_to_string(&mut raw).unwrap();
        let mut my_parser  = EventReader::from_str(&raw);
        let my_stack = my_parser.into_iter().peekable();
        let mut reader = XmlResponse::new(my_stack);
        reader.next(); // xml start node
        let result = ListMultipartUploadsOutputDeserializer::deserialize("ListMultipartUploadsResult", &mut reader);

        match result {
            Err(_) => panic!("Couldn't parse s3_list_multipart_uploads.xml"),
            Ok(result) => {
                assert_eq!(result.bucket, sstr("rusoto1440826511"));
                assert!(result.uploads.is_some());

                let an_upload = &result.uploads.unwrap()[0];
                assert_eq!(an_upload.upload_id, sstr("eUeGzA6xR2jAH7KUhTSwrrNVfu8XPIYdoWpa7meOiceoGQLQhtKfPg_APCnuVRsyWd7bx8SS5jNssgdtTU5tTziGOz.j1URgseoqpdHqnyZRikJHTLd6iXF.GjKBEhky"));
                assert_eq!(an_upload.key, sstr("join.me.zip"));

                let test_initiator = Initiator {
                    id: sstr("arn:aws:iam::347452556412:user/matthew"),
                    display_name: sstr("matthew") 
                };
<commit_msg>fix tests<commit_after>//! The AWS S3 API.

include!(concat!(env!("OUT_DIR"), "/s3.rs"));

#[cfg(test)]
mod test {
    use std::io::{Read, BufReader};
    use std::fs::File;
    use s3::{S3Client, HeadObjectRequest, GetObjectRequest, ListMultipartUploadsRequest};
    use s3::{CreateMultipartUploadOutputDeserializer, CompleteMultipartUploadOutputDeserializer};
    use s3::{ListMultipartUploadsOutputDeserializer, ListPartsRequest, Initiator, Owner};
    use xmlutil::{XmlResponse, Next};
    use xml::EventReader;

    use super::super::{Region, SignedRequest};
    use super::super::mock::*;

    extern crate env_logger;

    #[test]
    fn initiate_multipart_upload_happy_path() {
        let file = File::open("tests/sample-data/s3_initiate_multipart_upload.xml").unwrap();
        let mut file = BufReader::new(file);
        let mut raw = String::new();
        file.read_to_string(&mut raw).unwrap();
        let my_parser  = EventReader::from_str(&raw);
        let my_stack = my_parser.into_iter().peekable();
        let mut reader = XmlResponse::new(my_stack);
        reader.next(); // xml start node
        let result = CreateMultipartUploadOutputDeserializer::deserialize("InitiateMultipartUploadResult", &mut reader);

        match result {
            Err(_) => panic!("Couldn't parse initiate_multipart_upload"),
            Ok(result) => {
                assert_eq!(sstr("example-bucket"), result.bucket);
                assert_eq!(sstr("example-object"), result.key);
                assert_eq!(sstr("VXBsb2FkIElEIGZvciA2aWWpbmcncyBteS1tb3ZpZS5tMnRzIHVwbG9hZA"), result.upload_id);
            }
        }
    }

    #[test]
    fn complete_multipart_upload_happy_path() {
        let file = File::open("tests/sample-data/s3_complete_multipart_upload.xml").unwrap();
        let mut file = BufReader::new(file);
        let mut raw = String::new();
        file.read_to_string(&mut raw).unwrap();
        let my_parser  = EventReader::from_str(&raw);
        let my_stack = my_parser.into_iter().peekable();
        let mut reader = XmlResponse::new(my_stack);
        reader.next(); // xml start node
        let result = CompleteMultipartUploadOutputDeserializer::deserialize("CompleteMultipartUploadResult", &mut reader);

        match result {
            Err(_) => panic!("Couldn't parse s3_complete_multipart_upload"),
            Ok(result) => {
                assert_eq!(result.bucket, sstr("testbucket2"));
                assert_eq!(result.key, sstr("foo.zip"));
                assert_eq!(result.e_tag, sstr("\"525a81fcbc4181997bd96e4096fa7304-1\""));
            }
        }
    }

    #[test]
    fn list_multipart_upload_happy_path() {
        let file = File::open("tests/sample-data/s3_list_multipart_uploads.xml").unwrap();
        let mut file = BufReader::new(file);
        let mut raw = String::new();
        file.read_to_string(&mut raw).unwrap();
        let my_parser  = EventReader::from_str(&raw);
        let my_stack = my_parser.into_iter().peekable();
        let mut reader = XmlResponse::new(my_stack);
        reader.next(); // xml start node
        let result = ListMultipartUploadsOutputDeserializer::deserialize("ListMultipartUploadsResult", &mut reader);

        match result {
            Err(_) => panic!("Couldn't parse s3_list_multipart_uploads.xml"),
            Ok(result) => {
                assert_eq!(result.bucket, sstr("rusoto1440826511"));
                assert!(result.uploads.is_some());

                let an_upload = &result.uploads.unwrap()[0];
                assert_eq!(an_upload.upload_id, sstr("eUeGzA6xR2jAH7KUhTSwrrNVfu8XPIYdoWpa7meOiceoGQLQhtKfPg_APCnuVRsyWd7bx8SS5jNssgdtTU5tTziGOz.j1URgseoqpdHqnyZRikJHTLd6iXF.GjKBEhky"));
                assert_eq!(an_upload.key, sstr("join.me.zip"));

                let test_initiator = Initiator {
                    id: sstr("arn:aws:iam::347452556412:user/matthew"),
                    display_name: sstr("matthew") 
                };

{'fraction_non_alphanumeric': 0.1324402881334513, 'fraction_numerical': 0.01819790218627575, 'mean_word_length': 2.9471321695760597, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6756174', 'n_tokens_mistral': 2598, 'n_tokens_neox': 2480, 'n_words': 396}