From 06214c1caefd77bef6691317c8037f0908b3ebbe Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Sat, 21 Jan 2017 05:38:44 +0530 Subject: [PATCH] Clean up xml gen/parsing unit tests --- test/Network/Minio/XmlGenerator/Test.hs | 12 ++++- test/Network/Minio/XmlParser/Test.hs | 62 ++++++++++--------------- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/test/Network/Minio/XmlGenerator/Test.hs b/test/Network/Minio/XmlGenerator/Test.hs index e445a21..516d075 100644 --- a/test/Network/Minio/XmlGenerator/Test.hs +++ b/test/Network/Minio/XmlGenerator/Test.hs @@ -21,11 +21,19 @@ testMkCreateBucketConfig = do assertEqual "CreateBucketConfiguration xml should match: " expected $ mkCreateBucketConfig "EU" where - expected = "EU" + expected = "\ + \\ + \EU\ + \" testMkCompleteMultipartUploadRequest :: Assertion testMkCompleteMultipartUploadRequest = assertEqual "completeMultipartUpload xml should match: " expected $ mkCompleteMultipartUploadRequest [PartInfo 1 "abc"] where - expected = "1abc" + expected = "\ + \\ + \\ + \1abc\ + \\ + \" diff --git a/test/Network/Minio/XmlParser/Test.hs b/test/Network/Minio/XmlParser/Test.hs index a4217d1..eb15d4b 100644 --- a/test/Network/Minio/XmlParser/Test.hs +++ b/test/Network/Minio/XmlParser/Test.hs @@ -17,45 +17,33 @@ xmlParserTests = testGroup "XML Parser Tests" , testCase "Test parseNewMultipartUpload" testParseNewMultipartUpload ] -euLocationXml :: LByteString -euLocationXml = "\ -\EU" - -badLocationXml :: LByteString -badLocationXml = "ClearlyInvalidXml" - -usLocationXml :: LByteString -usLocationXml = "" - -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 = do - -- 1. Test parsing of a valid location xml. - testValidParseLocation - -- 2. Test parsing of an invalid location xml. - testInvalidParseLocation - -- 3. Test parsing of a valid, empty location xml. - testEmptyParseLocation + -- 1. Test parsing of an invalid location constraint xml. + parsedLocationE <- runExceptT $ parseLocation "ClearlyInvalidXml" + case parsedLocationE of + Right loc -> assertFailure $ "Parsing should have failed => " ++ show parsedLocationE + Left _ -> return () + + 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. + ("\ + \EU", + "EU" + ) + , + -- 3. Test parsing of a valid, empty location xml. + ("", + "" + ) + ] + testParseNewMultipartUpload :: Assertion testParseNewMultipartUpload = do