Safe Haskell | Safe-Infered |
---|
Unittest helpers for ganeti-htools.
- maxMem :: Int
- maxDsk :: Int
- maxCpu :: Int
- maxSpindles :: Int
- maxVcpuRatio :: Double
- maxSpindleRatio :: Double
- maxNodes :: Int
- maxOpCodes :: Int
- (==?) :: (Show a, Eq a) => a -> a -> Property
- (/=?) :: (Show a, Eq a) => a -> a -> Property
- failTest :: String -> Property
- passTest :: Property
- pythonCmd :: IO String
- runPython :: String -> String -> IO (ExitCode, String, String)
- checkPythonResult :: (ExitCode, String, String) -> IO String
- newtype DNSChar = DNSChar {
- dnsGetChar :: Char
- genName :: Gen String
- genFQDN :: Gen String
- genUUID :: Gen String
- genMaybe :: Gen a -> Gen (Maybe a)
- newtype TagChar = TagChar {
- tagGetChar :: Char
- tagChar :: String
- genTag :: Gen [TagChar]
- genTags :: Gen [String]
- genFields :: Gen [String]
- genUniquesList :: (Eq a, Arbitrary a, Ord a) => Int -> Gen a -> Gen [a]
- newtype SmallRatio = SmallRatio Double
- genSetHelper :: Ord a => [a] -> Maybe Int -> Gen (Set a)
- genSet :: (Ord a, Bounded a, Enum a) => Maybe Int -> Gen (Set a)
- genIp4Addr :: Gen NonEmptyString
- genIp4AddrStr :: Gen String
- genIp4NetWithNetmask :: Int -> Gen NonEmptyString
- genIp4Net :: Gen NonEmptyString
- netmask2NumHosts :: Word8 -> Int
- genIp6Addr :: Gen String
- genIp6Net :: Gen String
- testSerialisation :: (Eq a, Show a, JSON a) => a -> Property
- resultProp :: Show a => GenericResult a b -> PropertyM IO b
- getSourceDir :: IO FilePath
- testDataFilename :: String -> String -> IO FilePath
- readTestData :: String -> IO String
- genSample :: Gen a -> IO a
- testParser :: (Show a, Eq a) => Parser a -> String -> a -> Assertion
- genPropParser :: (Show a, Eq a) => Parser a -> String -> a -> Property
- genNonNegative :: Gen Int
Constants
maxSpindles :: IntSource
Max spindles (1024, somewhat random value).
maxVcpuRatio :: DoubleSource
Max vcpu ratio (random value).
maxSpindleRatio :: DoubleSource
Max spindle ratio (random value).
Max nodes, used just to limit arbitrary instances for smaller opcode definitions (e.g. list of nodes in OpTestDelay).
maxOpCodes :: IntSource
Max opcodes or jobs in a submit job and submit many jobs.
Helper functions
(==?) :: (Show a, Eq a) => a -> a -> PropertySource
Checks for equality with proper annotation. The first argument is the computed value, the second one the expected value.
(/=?) :: (Show a, Eq a) => a -> a -> PropertySource
Checks for inequality with proper annotation. The first argument is the computed value, the second one the expected (not equal) value.
Return the python binary to use. If the PYTHON environment variable is defined, use its value, otherwise use just "python".
runPython :: String -> String -> IO (ExitCode, String, String)Source
Run Python with an expression, returning the exit code, standard output and error.
checkPythonResult :: (ExitCode, String, String) -> IO StringSource
Check python exit code, and fail via HUnit assertions if non-zero. Otherwise, return the standard output.
Arbitrary instances
Generates a UUID-like string.
Only to be used for QuickCheck testing. For obtaining actual UUIDs use the newUUID function in Ganeti.Utils
genFields :: Gen [String]Source
Generates a fields list. This uses the same character set as a DNS name (just for simplicity).
genUniquesList :: (Eq a, Arbitrary a, Ord a) => Int -> Gen a -> Gen [a]Source
Generates a list of a given size with non-duplicate elements.
genSetHelper :: Ord a => [a] -> Maybe Int -> Gen (Set a)Source
Helper for genSet
, declared separately due to type constraints.
genSet :: (Ord a, Bounded a, Enum a) => Maybe Int -> Gen (Set a)Source
Generates a set of arbitrary elements.
genIp4Addr :: Gen NonEmptyStringSource
Generate an arbitrary IPv4 address in textual form (non empty).
genIp4AddrStr :: Gen StringSource
Generate an arbitrary IPv4 address in textual form.
genIp4NetWithNetmask :: Int -> Gen NonEmptyStringSource
Generates an arbitrary IPv4 address with a given netmask in textual form.
genIp4Net :: Gen NonEmptyStringSource
Generate an arbitrary IPv4 network in textual form.
netmask2NumHosts :: Word8 -> IntSource
Helper function to compute the number of hosts in a network given the netmask. (For IPv4 only.)
genIp6Addr :: Gen StringSource
Generates an arbitrary IPv6 network address in textual form. The generated address is not simpflified, e. g. an address like 2607:f0d0:1002:0051:0000:0000:0000:0004 does not become 2607:f0d0:1002:51::4
Helper functions
testSerialisation :: (Eq a, Show a, JSON a) => a -> PropertySource
Checks for serialisation idempotence.
resultProp :: Show a => GenericResult a b -> PropertyM IO bSource
Result to PropertyM IO.
getSourceDir :: IO FilePathSource
testDataFilename :: String -> String -> IO FilePathSource
readTestData :: String -> IO StringSource
Returns the content of the specified haskell test data file.
genSample :: Gen a -> IO aSource
Generate arbitrary values in the IO monad. This is a simple
wrapper over sample'
.
testParser :: (Show a, Eq a) => Parser a -> String -> a -> AssertionSource
Function for testing whether a file is parsed correctly.
genPropParser :: (Show a, Eq a) => Parser a -> String -> a -> PropertySource
Generate a property test for parsers.
genNonNegative :: Gen IntSource
Generate an arbitrary non negative integer number