Revision b6aeda4a
b/src/Ganeti/Utils.hs | ||
---|---|---|
45 | 45 |
, exitUnless |
46 | 46 |
, rStripSpace |
47 | 47 |
, newUUID |
48 |
, clockTimeToString |
|
48 | 49 |
) where |
49 | 50 |
|
50 | 51 |
import Data.Char (toUpper, isAlphaNum, isDigit, isSpace) |
... | ... | |
57 | 58 |
import qualified Ganeti.Constants as C |
58 | 59 |
import System.IO |
59 | 60 |
import System.Exit |
61 |
import System.Time |
|
60 | 62 |
|
61 | 63 |
-- * Debug functions |
62 | 64 |
|
... | ... | |
286 | 288 |
newUUID = do |
287 | 289 |
contents <- readFile C.randomUuidFile |
288 | 290 |
return $! rStripSpace $ take 128 contents |
291 |
|
|
292 |
-- | Convert a ClockTime into a (seconds-only) timestamp. |
|
293 |
clockTimeToString :: ClockTime -> String |
|
294 |
clockTimeToString (TOD t _) = show t |
b/test/hs/Test/Ganeti/Utils.hs | ||
---|---|---|
33 | 33 |
|
34 | 34 |
import Data.Char (isSpace) |
35 | 35 |
import Data.List |
36 |
import System.Time |
|
36 | 37 |
import qualified Text.JSON as J |
37 | 38 |
#ifndef NO_REGEX_PCRE |
38 | 39 |
import Text.Regex.PCRE |
... | ... | |
233 | 234 |
assertBool "newUUID" $ uuid =~ C.uuidRegex |
234 | 235 |
#endif |
235 | 236 |
|
237 |
prop_clockTimeToString :: Integer -> Integer -> Property |
|
238 |
prop_clockTimeToString ts pico = |
|
239 |
clockTimeToString (TOD ts pico) ==? show ts |
|
240 |
|
|
236 | 241 |
-- | Test list for the Utils module. |
237 | 242 |
testSuite "Utils" |
238 | 243 |
[ 'prop_commaJoinSplit |
... | ... | |
252 | 257 |
#ifndef NO_REGEX_PCRE |
253 | 258 |
, 'case_new_uuid |
254 | 259 |
#endif |
260 |
, 'prop_clockTimeToString |
|
255 | 261 |
] |
Also available in: Unified diff