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
|
||||
type: exitcode-stdio-1.0
|
||||
hs-source-dirs: test
|
||||
hs-source-dirs: test, src
|
||||
main-is: Spec.hs
|
||||
build-depends: base
|
||||
, minio-hs
|
||||
, 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
|
||||
, tasty
|
||||
, tasty-smallcheck
|
||||
, tasty-quickcheck
|
||||
, tasty-hunit
|
||||
, tasty-quickcheck
|
||||
, tasty-smallcheck
|
||||
, text
|
||||
, time
|
||||
, transformers
|
||||
, transformers-base
|
||||
, xml-conduit
|
||||
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
|
||||
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
|
||||
type: git
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
module Network.Minio.Data
|
||||
( ConnectInfo(..)
|
||||
, RequestInfo(..)
|
||||
-- , ResponseInfo(..)
|
||||
, MinioConn(..)
|
||||
, Bucket
|
||||
, Object
|
||||
|
||||
@ -45,7 +45,7 @@ putBucket :: Bucket -> Location -> Minio ()
|
||||
putBucket bucket location = do
|
||||
void $ executeRequest $
|
||||
requestInfo HT.methodPut (Just bucket) Nothing [] [] $
|
||||
Just $ mkCreateBucketConfig bucket location
|
||||
Just $ mkCreateBucketConfig location
|
||||
|
||||
deleteBucket :: Bucket -> Minio ()
|
||||
deleteBucket bucket = do
|
||||
|
||||
@ -10,11 +10,13 @@ import qualified Data.Map as M
|
||||
|
||||
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
|
||||
root = Element (s3Name "CreateBucketConfiguration") M.empty
|
||||
[ NodeElement $ Element "LocationConstraint" M.empty
|
||||
s3Element n = Element (s3Name n) M.empty
|
||||
root = s3Element "CreateBucketConfiguration"
|
||||
[ NodeElement $ s3Element "LocationConstraint"
|
||||
[ NodeContent location]
|
||||
]
|
||||
bucketConfig = Document (Prologue [] Nothing []) root []
|
||||
|
||||
19
test/Spec.hs
19
test/Spec.hs
@ -1,13 +1,12 @@
|
||||
import Protolude
|
||||
|
||||
import Test.Tasty
|
||||
import Test.Tasty.SmallCheck as SC
|
||||
import Test.Tasty.QuickCheck as QC
|
||||
import Test.Tasty.HUnit
|
||||
|
||||
import Control.Monad.Trans.Resource (runResourceT)
|
||||
|
||||
import Network.Minio
|
||||
import Network.Minio.XmlGenerator
|
||||
|
||||
main :: IO ()
|
||||
main = defaultMain tests
|
||||
@ -41,11 +40,9 @@ properties = testGroup "Properties" [] -- [scProps, qcProps]
|
||||
-- (n :: Integer) >= 3 QC.==> x^n + y^n /= (z^n :: Integer)
|
||||
-- ]
|
||||
|
||||
unitTests :: TestTree
|
||||
unitTests = testGroup "Unit tests"
|
||||
[ testCase "List comparison (different length)" $
|
||||
[1, 2, 3] `compare` [1,2] @?= GT,
|
||||
|
||||
testCaseSteps "Check getService returns without exception" $ \step -> do
|
||||
[ testCaseSteps "Check getService returns without exception" $ \step -> do
|
||||
step "Preparing..."
|
||||
|
||||
mc <- connect defaultConnectInfo
|
||||
@ -54,4 +51,14 @@ unitTests = testGroup "Unit tests"
|
||||
ret <- runResourceT $ runMinio mc $ getService
|
||||
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