Make internal functions available for testing
This commit is contained in:
parent
a7e70b9031
commit
b9c7ceb435
@ -72,19 +72,54 @@ executable minio-hs-exe
|
|||||||
|
|
||||||
test-suite minio-hs-test
|
test-suite minio-hs-test
|
||||||
type: exitcode-stdio-1.0
|
type: exitcode-stdio-1.0
|
||||||
hs-source-dirs: test
|
hs-source-dirs: test, src
|
||||||
main-is: Spec.hs
|
main-is: Spec.hs
|
||||||
build-depends: base
|
build-depends: base
|
||||||
, minio-hs
|
, minio-hs
|
||||||
, protolude >= 0.1.6 && < 0.2
|
, protolude >= 0.1.6 && < 0.2
|
||||||
|
, bytestring
|
||||||
|
, case-insensitive
|
||||||
|
, conduit
|
||||||
|
, conduit-combinators
|
||||||
|
, conduit-extra
|
||||||
|
, containers
|
||||||
|
, cryptonite
|
||||||
|
, errors
|
||||||
|
, filepath
|
||||||
|
, http-client
|
||||||
|
, http-conduit
|
||||||
|
, http-types
|
||||||
|
, memory
|
||||||
, resourcet
|
, resourcet
|
||||||
, tasty
|
, tasty
|
||||||
, tasty-smallcheck
|
|
||||||
, tasty-quickcheck
|
|
||||||
, tasty-hunit
|
, tasty-hunit
|
||||||
|
, tasty-quickcheck
|
||||||
|
, tasty-smallcheck
|
||||||
|
, text
|
||||||
|
, time
|
||||||
|
, transformers
|
||||||
|
, transformers-base
|
||||||
|
, xml-conduit
|
||||||
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
|
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
default-extensions: OverloadedStrings, NoImplicitPrelude
|
default-extensions: FlexibleContexts
|
||||||
|
, FlexibleInstances
|
||||||
|
, OverloadedStrings
|
||||||
|
, NoImplicitPrelude
|
||||||
|
, MultiParamTypeClasses
|
||||||
|
, MultiWayIf
|
||||||
|
other-modules: Lib.Prelude
|
||||||
|
, Network.Minio
|
||||||
|
, Network.Minio.API
|
||||||
|
, Network.Minio.Data
|
||||||
|
, Network.Minio.Data.ByteString
|
||||||
|
, Network.Minio.Data.Crypto
|
||||||
|
, Network.Minio.Data.Time
|
||||||
|
, Network.Minio.S3API
|
||||||
|
, Network.Minio.Sign.V4
|
||||||
|
, Network.Minio.XmlGenerator
|
||||||
|
, Network.Minio.XmlParser
|
||||||
|
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
module Network.Minio.Data
|
module Network.Minio.Data
|
||||||
( ConnectInfo(..)
|
( ConnectInfo(..)
|
||||||
, RequestInfo(..)
|
, RequestInfo(..)
|
||||||
-- , ResponseInfo(..)
|
|
||||||
, MinioConn(..)
|
, MinioConn(..)
|
||||||
, Bucket
|
, Bucket
|
||||||
, Object
|
, Object
|
||||||
|
|||||||
@ -45,7 +45,7 @@ putBucket :: Bucket -> Location -> Minio ()
|
|||||||
putBucket bucket location = do
|
putBucket bucket location = do
|
||||||
void $ executeRequest $
|
void $ executeRequest $
|
||||||
requestInfo HT.methodPut (Just bucket) Nothing [] [] $
|
requestInfo HT.methodPut (Just bucket) Nothing [] [] $
|
||||||
Just $ mkCreateBucketConfig bucket location
|
Just $ mkCreateBucketConfig location
|
||||||
|
|
||||||
deleteBucket :: Bucket -> Minio ()
|
deleteBucket :: Bucket -> Minio ()
|
||||||
deleteBucket bucket = do
|
deleteBucket bucket = do
|
||||||
|
|||||||
@ -10,11 +10,13 @@ import qualified Data.Map as M
|
|||||||
|
|
||||||
import Network.Minio.Data
|
import Network.Minio.Data
|
||||||
|
|
||||||
mkCreateBucketConfig :: Bucket -> Location -> ByteString
|
|
||||||
mkCreateBucketConfig bucket location = LBS.toStrict $ renderLBS def bucketConfig
|
mkCreateBucketConfig :: Location -> ByteString
|
||||||
|
mkCreateBucketConfig location = LBS.toStrict $ renderLBS def bucketConfig
|
||||||
where
|
where
|
||||||
root = Element (s3Name "CreateBucketConfiguration") M.empty
|
s3Element n = Element (s3Name n) M.empty
|
||||||
[ NodeElement $ Element "LocationConstraint" M.empty
|
root = s3Element "CreateBucketConfiguration"
|
||||||
|
[ NodeElement $ s3Element "LocationConstraint"
|
||||||
[ NodeContent location]
|
[ NodeContent location]
|
||||||
]
|
]
|
||||||
bucketConfig = Document (Prologue [] Nothing []) root []
|
bucketConfig = Document (Prologue [] Nothing []) root []
|
||||||
|
|||||||
19
test/Spec.hs
19
test/Spec.hs
@ -1,13 +1,12 @@
|
|||||||
import Protolude
|
import Protolude
|
||||||
|
|
||||||
import Test.Tasty
|
import Test.Tasty
|
||||||
import Test.Tasty.SmallCheck as SC
|
|
||||||
import Test.Tasty.QuickCheck as QC
|
|
||||||
import Test.Tasty.HUnit
|
import Test.Tasty.HUnit
|
||||||
|
|
||||||
import Control.Monad.Trans.Resource (runResourceT)
|
import Control.Monad.Trans.Resource (runResourceT)
|
||||||
|
|
||||||
import Network.Minio
|
import Network.Minio
|
||||||
|
import Network.Minio.XmlGenerator
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = defaultMain tests
|
main = defaultMain tests
|
||||||
@ -41,11 +40,9 @@ properties = testGroup "Properties" [] -- [scProps, qcProps]
|
|||||||
-- (n :: Integer) >= 3 QC.==> x^n + y^n /= (z^n :: Integer)
|
-- (n :: Integer) >= 3 QC.==> x^n + y^n /= (z^n :: Integer)
|
||||||
-- ]
|
-- ]
|
||||||
|
|
||||||
|
unitTests :: TestTree
|
||||||
unitTests = testGroup "Unit tests"
|
unitTests = testGroup "Unit tests"
|
||||||
[ testCase "List comparison (different length)" $
|
[ testCaseSteps "Check getService returns without exception" $ \step -> do
|
||||||
[1, 2, 3] `compare` [1,2] @?= GT,
|
|
||||||
|
|
||||||
testCaseSteps "Check getService returns without exception" $ \step -> do
|
|
||||||
step "Preparing..."
|
step "Preparing..."
|
||||||
|
|
||||||
mc <- connect defaultConnectInfo
|
mc <- connect defaultConnectInfo
|
||||||
@ -54,4 +51,14 @@ unitTests = testGroup "Unit tests"
|
|||||||
ret <- runResourceT $ runMinio mc $ getService
|
ret <- runResourceT $ runMinio mc $ getService
|
||||||
isRight ret @? ("getService failure => " ++ show ret)
|
isRight ret @? ("getService failure => " ++ show ret)
|
||||||
|
|
||||||
|
, testCase "Test mkCreateBucketConfig." testMkCreateBucketConfig
|
||||||
]
|
]
|
||||||
|
|
||||||
|
usEastBucketConfig :: ByteString
|
||||||
|
usEastBucketConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><CreateBucketConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\
|
||||||
|
\<LocationConstraint>EU</LocationConstraint>\
|
||||||
|
\</CreateBucketConfiguration>"
|
||||||
|
|
||||||
|
testMkCreateBucketConfig :: Assertion
|
||||||
|
testMkCreateBucketConfig = do
|
||||||
|
assertEqual "CreateBucketConfiguration xml should match: " usEastBucketConfig $ mkCreateBucketConfig "EU"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user