Revision 305e174c htest/Test/Ganeti/TestCommon.hs
b/htest/Test/Ganeti/TestCommon.hs | ||
---|---|---|
108 | 108 |
if bool |
109 | 109 |
then Just <$> subgen |
110 | 110 |
else return Nothing |
111 |
|
|
112 |
-- | Defines a tag type. |
|
113 |
newtype TagChar = TagChar { tagGetChar :: Char } |
|
114 |
|
|
115 |
-- | All valid tag chars. This doesn't need to match _exactly_ |
|
116 |
-- Ganeti's own tag regex, just enough for it to be close. |
|
117 |
tagChar :: [Char] |
|
118 |
tagChar = ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ ".+*/:@-" |
|
119 |
|
|
120 |
instance Arbitrary TagChar where |
|
121 |
arbitrary = do |
|
122 |
c <- elements tagChar |
|
123 |
return (TagChar c) |
|
124 |
|
|
125 |
-- | Generates a tag |
|
126 |
genTag :: Gen [TagChar] |
|
127 |
genTag = do |
|
128 |
-- the correct value would be C.maxTagLen, but that's way too |
|
129 |
-- verbose in unittests, and at the moment I don't see any possible |
|
130 |
-- bugs with longer tags and the way we use tags in htools |
|
131 |
n <- choose (1, 10) |
|
132 |
vector n |
|
133 |
|
|
134 |
-- | Generates a list of tags (correctly upper bounded). |
|
135 |
genTags :: Gen [String] |
|
136 |
genTags = do |
|
137 |
-- the correct value would be C.maxTagsPerObj, but per the comment |
|
138 |
-- in genTag, we don't use tags enough in htools to warrant testing |
|
139 |
-- such big values |
|
140 |
n <- choose (0, 10::Int) |
|
141 |
tags <- mapM (const genTag) [1..n] |
|
142 |
return $ map (map tagGetChar) tags |
Also available in: Unified diff