Safe Haskell | None |
---|
Common helper functions and instances for all Ganeti tests.
Synopsis
- 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
- cover' :: Testable prop => Double -> Bool -> String -> prop -> Property
- stableCover :: Testable prop => Bool -> Double -> String -> prop -> Property
- pythonCmd :: IO String
- runPython :: String -> String -> IO (ExitCode, String, String)
- checkPythonResult :: (ExitCode, String, String) -> IO String
- newtype DNSChar = DNSChar {
- dnsGetChar :: Char
- genPrintableAsciiChar :: Gen Char
- genPrintableAsciiString :: Gen String
- genPrintableAsciiStringNE :: Gen NonEmptyString
- genPrintableByteString :: Gen ByteString
- genName :: Gen String
- genFQDN :: Gen String
- genUUID :: Gen String
- genMaybe :: Gen a -> Gen (Maybe a)
- genSublist :: [a] -> Gen [a]
- genMap :: (Ord k, Ord v) => Gen k -> Gen v -> Gen (Map k v)
- 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)
- genListSet :: (Ord a, Bounded a, Enum a) => Maybe Int -> Gen (ListSet a)
- genAndRestArguments :: Gen (Map String JSValue)
- genIPv4 :: Gen String
- genIPv4Address :: Gen IPv4Address
- genIPv4AddrRange :: Gen String
- genIPv4Network :: Gen IPv4Network
- netmask2NumHosts :: Word8 -> Int
- genIp6Addr :: Gen String
- ip6AddressFromNumber :: Integer -> [Char]
- genIp6Net :: Gen String
- genOpCodesTagName :: TagKind -> Gen (Maybe String)
- genLuxiTagName :: TagKind -> Gen String
- testSerialisation :: (Eq a, Show a, JSON a) => a -> Property
- testArraySerialisation :: (Eq a, Show a, ArrayObject a) => a -> Property
- testDeserialisationFail :: (Eq a, Show a, JSON a) => a -> JSValue -> 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
- relativeError :: Double -> Double -> Double
- getTempFileName :: String -> IO FilePath
- listOfUniqueBy :: Ord b => Gen a -> (a -> b) -> [a] -> Gen [a]
Compatibility instances
Arbitrary orphan instances
Constants
maxSpindles :: Int Source #
Max spindles (1024, somewhat random value).
maxVcpuRatio :: Double Source #
Max vcpu ratio (random value).
maxSpindleRatio :: Double Source #
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 :: Int Source #
Max opcodes or jobs in a submit job and submit many jobs.
Helper functions
(==?) :: (Show a, Eq a) => a -> a -> Property infix 3 Source #
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 -> Property infix 3 Source #
Checks for inequality with proper annotation. The first argument is the computed value, the second one the expected (not equal) value.
cover' :: Testable prop => Double -> Bool -> String -> prop -> Property Source #
QuickCheck 2.12 swapped the order of the first two arguments, so provide a compatibility function here
stableCover :: Testable prop => Bool -> Double -> String -> prop -> Property Source #
A stable version of QuickCheck's cover
. In its current implementation,
cover will not detect insufficient coverage if the actual coverage in the
sample is 0. Work around this by lifting the probability to at least
10 percent.
The underlying issue is tracked at
https://github.com/nick8325/quickcheck/issues/26
pythonCmd :: IO String Source #
Return the python binary to use. If the PYTHON environment variable is defined, use its value, otherwise use just "python3".
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 String Source #
Check python exit code, and fail via HUnit assertions if non-zero. Otherwise, return the standard output.
Arbitrary instances
Defines a DNS name.
DNSChar | |
|
Generators
genPrintableAsciiChar :: Gen Char Source #
Generates printable ASCII characters (from ' ' to '~').
genPrintableAsciiString :: Gen String Source #
Generates a short string (0 <= n <= 40 chars) from printable ASCII.
genPrintableAsciiStringNE :: Gen NonEmptyString Source #
Generates a short string (1 <= n <= 40 chars) from printable ASCII.
genPrintableByteString :: Gen ByteString Source #
Generates a printable Unicode ByteString
genUUID :: Gen String Source #
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.
All valid tag chars. This doesn't need to match _exactly_ Ganeti's own tag regex, just enough for it to be close.
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 #
SmallRatio Double |
Instances
Show SmallRatio # | |
Defined in Test.Ganeti.TestCommon showsPrec :: Int -> SmallRatio -> ShowS show :: SmallRatio -> String showList :: [SmallRatio] -> ShowS | |
Arbitrary SmallRatio # | |
Defined in Test.Ganeti.TestCommon arbitrary :: Gen SmallRatio shrink :: SmallRatio -> [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.
genIPv4Address :: Gen IPv4Address Source #
genIPv4AddrRange :: Gen String Source #
Generate an arbitrary IPv4 network in textual form.
genIPv4Network :: Gen IPv4Network Source #
netmask2NumHosts :: Word8 -> Int Source #
Helper function to compute the number of hosts in a network given the netmask. (For IPv4 only.)
genIp6Addr :: Gen String Source #
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"
ip6AddressFromNumber :: Integer -> [Char] Source #
Helper function to convert an integer in to an IPv6 address 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 String Source #
Generates a valid, arbitrary tag name with respect to the given
TagKind
for Luxi.
Helper functions
testSerialisation :: (Eq a, Show a, JSON a) => a -> Property Source #
Checks for serialisation idempotence.
testArraySerialisation :: (Eq a, Show a, ArrayObject a) => a -> Property Source #
Checks for array serialisation idempotence.
testDeserialisationFail :: (Eq a, Show a, JSON a) => a -> JSValue -> Property Source #
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 b Source #
Result to PropertyM IO.
getSourceDir :: IO FilePath Source #
Return the source directory of Ganeti.
testDataFilename :: String -> String -> IO FilePath Source #
Returns the path of a file in the test data directory, given its name.
readTestData :: String -> IO String Source #
Returns the content of the specified haskell test data file.
genSample :: Gen a -> IO a Source #
Generate arbitrary values in the IO monad. This is a simple
wrapper over sample'
.
testParser :: (Show a, Eq a) => Parser a -> String -> a -> Assertion Source #
Function for testing whether a file is parsed correctly.
genPropParser :: (Show a, Eq a) => Parser a -> String -> a -> Property Source #
Generate a property test for parsers.
genNonNegative :: Gen Int Source #
Generate an arbitrary non negative integer number
relativeError :: Double -> Double -> Double Source #
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 FilePath Source #
Helper to a get a temporary file name.
listOfUniqueBy :: Ord b => Gen a -> (a -> b) -> [a] -> Gen [a] Source #
listOfUniqueBy gen keyFun forbidden
: Generates a list of random length,
where all generated elements will be unique by the keying function
keyFun
. They will also be distinct from all elements in forbidden
by
the keying function.
As for listOf
, the maximum output length depends on the size parameter.
Example:
listOfUniqueBy (arbitrary :: Gen String) (length) ["hey"] -- Generates a list of strings of different length, but not of length 3.
The passed gen
should not make key collisions too likely, since the
implementation uses suchThat
, looping until enough unique elements
have been generated. If the gen
makes collisions likely, this function
will consequently be slow, or not terminate if it is not possible to
generate enough elements, like in:
listOfUniqueBy (arbitrary :: Gen Int) (`mod` 2) [] -- May not terminate depending on the size parameter of the Gen, -- since there are only 2 unique keys (0 and 1).