ganeti

Safe HaskellSafe-Infered

Test.Ganeti.TestCommon

Contents

Description

Common helper functions and instances for all Ganeti tests.

Synopsis

Constants

maxMem :: IntSource

Maximum memory (1TiB, somewhat random value).

maxDsk :: IntSource

Maximum disk (8TiB, somewhat random value).

maxCpu :: IntSource

Max CPUs (1024, somewhat random value).

maxSpindles :: IntSource

Max spindles (1024, somewhat random value).

maxVcpuRatio :: DoubleSource

Max vcpu ratio (random value).

maxSpindleRatio :: DoubleSource

Max spindle ratio (random value).

maxNodes :: IntSource

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.

failTest :: String -> PropertySource

Show a message and fail the test.

passTest :: PropertySource

A True property.

pythonCmd :: IO StringSource

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

newtype DNSChar Source

Defines a DNS name.

Constructors

DNSChar 

Fields

dnsGetChar :: Char
 

Instances

Show DNSChar 
Arbitrary DNSChar 

genName :: Gen StringSource

Generates a single name component.

genFQDN :: Gen StringSource

Generates an entire FQDN.

genUUID :: Gen StringSource

Generates a UUID-like string.

Only to be used for QuickCheck testing. For obtaining actual UUIDs use the newUUID function in Ganeti.Utils

genMaybe :: Gen a -> Gen (Maybe a)Source

Combinator that generates a Maybe using a sub-combinator.

genSublist :: [a] -> Gen [a]Source

Generates a sublist of a given list, keeping the ordering. The generated elements are always a subset of the list.

In order to better support corner cases, the size of the sublist is chosen to have the uniform distribution.

genMap :: (Ord k, Ord v) => Gen k -> Gen v -> Gen (Map k v)Source

Generates a map given generators for keys and values.

newtype TagChar Source

Constructors

TagChar 

Fields

tagGetChar :: Char
 

Instances

Arbitrary TagChar 

tagChar :: StringSource

genTags :: Gen [String]Source

Generates a list of tags (correctly upper bounded).

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.

newtype SmallRatio Source

Constructors

SmallRatio Double 

Instances

Show SmallRatio 
Arbitrary SmallRatio 

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.

genListSet :: (Ord a, Bounded a, Enum a) => Maybe Int -> Gen (ListSet a)Source

Generates a Set of arbitrary elements wrapped in a ListSet

genAndRestArguments :: Gen (Map String JSValue)Source

Generate an arbitrary element of and AndRestArguments field.

genIPv4 :: Gen StringSource

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

genIp6Net :: Gen StringSource

Generates an arbitrary IPv6 network in textual form.

genOpCodesTagName :: TagKind -> Gen (Maybe String)Source

Generates a valid, arbitrary tag name with respect to the given TagKind for opcodes.

genLuxiTagName :: TagKind -> Gen StringSource

Generates a valid, arbitrary tag name with respect to the given TagKind for Luxi.

Helper functions

testSerialisation :: (Eq a, Show a, JSON a) => a -> PropertySource

Checks for serialisation idempotence.

testArraySerialisation :: (Eq a, Show a, ArrayObject a) => a -> PropertySource

Checks for array serialisation idempotence.

testDeserialisationFail :: (Eq a, Show a, JSON a) => a -> JSValue -> PropertySource

Checks if the deserializer doesn't accept forbidden values. The first argument is ignored, it just enforces the correct type.

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

relativeError :: Double -> Double -> DoubleSource

Computes the relative error of two Double numbers.

This is the "relative error" algorithm in http://randomascii.wordpress.com/2012/02/25/ comparing-floating-point-numbers-2012-edition (URL split due to too long line).

getTempFileName :: String -> IO FilePathSource

Helper to a get a temporary file name.

counterexample :: Testable prop => String -> prop -> PropertySource