Clean up xml gen/parsing unit tests
This commit is contained in:
parent
2070a8e13f
commit
06214c1cae
@ -21,11 +21,19 @@ testMkCreateBucketConfig = do
|
|||||||
assertEqual "CreateBucketConfiguration xml should match: " expected $
|
assertEqual "CreateBucketConfiguration xml should match: " expected $
|
||||||
mkCreateBucketConfig "EU"
|
mkCreateBucketConfig "EU"
|
||||||
where
|
where
|
||||||
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><CreateBucketConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>"
|
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
|
||||||
|
\<CreateBucketConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\
|
||||||
|
\<LocationConstraint>EU</LocationConstraint>\
|
||||||
|
\</CreateBucketConfiguration>"
|
||||||
|
|
||||||
testMkCompleteMultipartUploadRequest :: Assertion
|
testMkCompleteMultipartUploadRequest :: Assertion
|
||||||
testMkCompleteMultipartUploadRequest =
|
testMkCompleteMultipartUploadRequest =
|
||||||
assertEqual "completeMultipartUpload xml should match: " expected $
|
assertEqual "completeMultipartUpload xml should match: " expected $
|
||||||
mkCompleteMultipartUploadRequest [PartInfo 1 "abc"]
|
mkCompleteMultipartUploadRequest [PartInfo 1 "abc"]
|
||||||
where
|
where
|
||||||
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><CompleteMultipartUpload><Part><PartNumber>1</PartNumber><ETag>abc</ETag></Part></CompleteMultipartUpload>"
|
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
|
||||||
|
\<CompleteMultipartUpload>\
|
||||||
|
\<Part>\
|
||||||
|
\<PartNumber>1</PartNumber><ETag>abc</ETag>\
|
||||||
|
\</Part>\
|
||||||
|
\</CompleteMultipartUpload>"
|
||||||
|
|||||||
@ -17,45 +17,33 @@ xmlParserTests = testGroup "XML Parser Tests"
|
|||||||
, testCase "Test parseNewMultipartUpload" testParseNewMultipartUpload
|
, testCase "Test parseNewMultipartUpload" testParseNewMultipartUpload
|
||||||
]
|
]
|
||||||
|
|
||||||
euLocationXml :: LByteString
|
|
||||||
euLocationXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
|
|
||||||
\<LocationConstraint xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">EU</LocationConstraint>"
|
|
||||||
|
|
||||||
badLocationXml :: LByteString
|
|
||||||
badLocationXml = "ClearlyInvalidXml"
|
|
||||||
|
|
||||||
usLocationXml :: LByteString
|
|
||||||
usLocationXml = "<LocationConstraint xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>"
|
|
||||||
|
|
||||||
testValidParseLocation :: Assertion
|
|
||||||
testValidParseLocation = do
|
|
||||||
txt <- runExceptT $ parseLocation euLocationXml
|
|
||||||
let location = case txt of
|
|
||||||
Right loc -> loc
|
|
||||||
Left _ -> ""
|
|
||||||
(isRight txt && location == "EU") @? ("Parsing failed unexpectedly => " ++ show txt)
|
|
||||||
|
|
||||||
testInvalidParseLocation :: Assertion
|
|
||||||
testInvalidParseLocation = do
|
|
||||||
txt <- runExceptT $ parseLocation badLocationXml
|
|
||||||
(isLeft txt) @? ("Parsing succeeded unexpectedly => " ++ show txt)
|
|
||||||
|
|
||||||
testEmptyParseLocation :: Assertion
|
|
||||||
testEmptyParseLocation = do
|
|
||||||
txt <- runExceptT $ parseLocation usLocationXml
|
|
||||||
let location = case txt of
|
|
||||||
Right loc -> loc
|
|
||||||
Left _ -> ""
|
|
||||||
(isRight txt && location == "") @? ("Parsing failed unexpectedly => " ++ show txt)
|
|
||||||
|
|
||||||
testParseLocation :: Assertion
|
testParseLocation :: Assertion
|
||||||
testParseLocation = do
|
testParseLocation = do
|
||||||
-- 1. Test parsing of a valid location xml.
|
-- 1. Test parsing of an invalid location constraint xml.
|
||||||
testValidParseLocation
|
parsedLocationE <- runExceptT $ parseLocation "ClearlyInvalidXml"
|
||||||
-- 2. Test parsing of an invalid location xml.
|
case parsedLocationE of
|
||||||
testInvalidParseLocation
|
Right loc -> assertFailure $ "Parsing should have failed => " ++ show parsedLocationE
|
||||||
-- 3. Test parsing of a valid, empty location xml.
|
Left _ -> return ()
|
||||||
testEmptyParseLocation
|
|
||||||
|
forM_ cases $ \(xmldata, expectedLocation) -> do
|
||||||
|
parsedLocationE <- runExceptT $ parseLocation xmldata
|
||||||
|
case parsedLocationE of
|
||||||
|
Right parsedLocation -> parsedLocation @?= expectedLocation
|
||||||
|
_ -> assertFailure $ "Parsing failed => " ++ show parsedLocationE
|
||||||
|
where
|
||||||
|
cases = [
|
||||||
|
-- 2. Test parsing of a valid location xml.
|
||||||
|
("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
|
||||||
|
\<LocationConstraint xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">EU</LocationConstraint>",
|
||||||
|
"EU"
|
||||||
|
)
|
||||||
|
,
|
||||||
|
-- 3. Test parsing of a valid, empty location xml.
|
||||||
|
("<LocationConstraint xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>",
|
||||||
|
""
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
testParseNewMultipartUpload :: Assertion
|
testParseNewMultipartUpload :: Assertion
|
||||||
testParseNewMultipartUpload = do
|
testParseNewMultipartUpload = do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user