From aabcf3dfec61028bbd892485ae1dc628bd32545e Mon Sep 17 00:00:00 2001 From: Aditya Manthramurthy Date: Thu, 19 Jan 2017 13:33:27 +0530 Subject: [PATCH] Restructure tests --- test/Network/Minio/XmlGenerator/Test.hs | 14 ++++++++-- test/Network/Minio/XmlParser/Test.hs | 37 +++++++++++++++++++++++-- test/Spec.hs | 13 ++++----- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/test/Network/Minio/XmlGenerator/Test.hs b/test/Network/Minio/XmlGenerator/Test.hs index 444f0a7..fe4d6f9 100644 --- a/test/Network/Minio/XmlGenerator/Test.hs +++ b/test/Network/Minio/XmlGenerator/Test.hs @@ -1,11 +1,19 @@ -module Network.Minio.XmlGenerator.Test where - -import Protolude +module Network.Minio.XmlGenerator.Test + ( xmlGeneratorTests + ) where +import Test.Tasty import Test.Tasty.HUnit +import Lib.Prelude + import Network.Minio.XmlGenerator +xmlGeneratorTests :: TestTree +xmlGeneratorTests = testGroup "XML Generator Tests" + [ testCase "Test mkCreateBucketConfig" testMkCreateBucketConfig + ] + euBucketConfig :: ByteString euBucketConfig = "\ \EU\ diff --git a/test/Network/Minio/XmlParser/Test.hs b/test/Network/Minio/XmlParser/Test.hs index 1cce1ae..a4217d1 100644 --- a/test/Network/Minio/XmlParser/Test.hs +++ b/test/Network/Minio/XmlParser/Test.hs @@ -1,15 +1,21 @@ module Network.Minio.XmlParser.Test ( - testParseLocation + xmlParserTests ) where +import Test.Tasty import Test.Tasty.HUnit import Lib.Prelude -import Network.Minio.Data +-- import Network.Minio.Data import Network.Minio.XmlParser +xmlParserTests :: TestTree +xmlParserTests = testGroup "XML Parser Tests" + [ testCase "Test parseLocation" testParseLocation + , testCase "Test parseNewMultipartUpload" testParseNewMultipartUpload + ] euLocationXml :: LByteString euLocationXml = "\ @@ -50,3 +56,30 @@ testParseLocation = do testInvalidParseLocation -- 3. Test parsing of a valid, empty location xml. testEmptyParseLocation + +testParseNewMultipartUpload :: Assertion +testParseNewMultipartUpload = do + forM_ cases $ \(xmldata, expectedUploadId) -> do + parsedUploadIdE <- runExceptT $ parseNewMultipartUpload xmldata + case parsedUploadIdE of + Right upId -> upId @?= expectedUploadId + _ -> assertFailure $ "Parsing failed => " ++ show parsedUploadIdE + where + cases = [ + ("\ + \\ + \ example-bucket\ + \ example-object\ + \ VXBsb2FkIElEIGZvciA2aWWpbmcncyBteS1tb3ZpZS5tMnRzIHVwbG9hZA\ + \", + "VXBsb2FkIElEIGZvciA2aWWpbmcncyBteS1tb3ZpZS5tMnRzIHVwbG9hZA" + ), + ("\ + \\ + \ example-bucket\ + \ example-object\ + \ EXAMPLEJZ6e0YupT2h66iePQCc9IEbYbDUy4RTpMeoSMLPRp8Z5o1u8feSRonpvnWsKKG35tI2LB9VDPiCgTy.Gq2VxQLYjrue4Nq.NBdqI-\ + \", + "EXAMPLEJZ6e0YupT2h66iePQCc9IEbYbDUy4RTpMeoSMLPRp8Z5o1u8feSRonpvnWsKKG35tI2LB9VDPiCgTy.Gq2VxQLYjrue4Nq.NBdqI-" + ) + ] diff --git a/test/Spec.hs b/test/Spec.hs index 78cf0e5..b368a10 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1,8 +1,8 @@ -import Protolude - import Test.Tasty import Test.Tasty.HUnit +import Lib.Prelude + -- import qualified System.IO as SIO import Control.Monad.Trans.Resource (runResourceT) @@ -77,6 +77,9 @@ liveServerUnitTests = testGroup "Unit tests against a live server" liftIO $ (T.length uid > 0) @? ("Got an empty newMultipartUpload Id => " ++ show mp) + liftIO $ step "abort a new multipart upload works" + abortMultipartUpload "testbucket" "newmpupload" uid + liftIO $ step "delete object works" deleteObject "testbucket" "lsb-release" @@ -88,8 +91,4 @@ liveServerUnitTests = testGroup "Unit tests against a live server" ] unitTests :: TestTree -unitTests = testGroup "Unit tests" - [ testCase "Test mkCreateBucketConfig." testMkCreateBucketConfig - - , testCase "Test parseLocation." testParseLocation - ] +unitTests = testGroup "Unit tests" [xmlGeneratorTests, xmlParserTests]