Revision 37fe56e0

b/src/Ganeti/Types.hs
11 11

  
12 12
{-
13 13

  
14
Copyright (C) 2012 Google Inc.
14
Copyright (C) 2012, 2013 Google Inc.
15 15

  
16 16
This program is free software; you can redistribute it and/or modify
17 17
it under the terms of the GNU General Public License as published by
......
86 86
  , JobDependency(..)
87 87
  , OpSubmitPriority(..)
88 88
  , opSubmitPriorityToRaw
89
  , parseSubmitPriority
90
  , fmtSubmitPriority
89 91
  , OpStatus(..)
90 92
  , opStatusToRaw
91 93
  , opStatusFromRaw
......
447 449
  ])
448 450
$(THH.makeJSONInstance ''OpSubmitPriority)
449 451

  
452
-- | Parse submit priorities from a string.
453
parseSubmitPriority :: (Monad m) => String -> m OpSubmitPriority
454
parseSubmitPriority "low"    = return OpPrioLow
455
parseSubmitPriority "normal" = return OpPrioNormal
456
parseSubmitPriority "high"   = return OpPrioHigh
457
parseSubmitPriority str      = fail $ "Unknown priority '" ++ str ++ "'"
458

  
459
-- | Format a submit priority as string.
460
fmtSubmitPriority :: OpSubmitPriority -> String
461
fmtSubmitPriority OpPrioLow    = "low"
462
fmtSubmitPriority OpPrioNormal = "normal"
463
fmtSubmitPriority OpPrioHigh   = "high"
464

  
450 465
-- | Our ADT for the OpCode status at runtime (while in a job).
451 466
$(THH.declareSADT "OpStatus"
452 467
  [ ("OP_STATUS_QUEUED",    'C.opStatusQueued)
b/test/hs/Test/Ganeti/Types.hs
7 7

  
8 8
{-
9 9

  
10
Copyright (C) 2012 Google Inc.
10
Copyright (C) 2012, 2013 Google Inc.
11 11

  
12 12
This program is free software; you can redistribute it and/or modify
13 13
it under the terms of the GNU General Public License as published by
......
370 370
prop_OpSubmitPriority_serialisation :: OpSubmitPriority -> Property
371 371
prop_OpSubmitPriority_serialisation = testSerialisation
372 372

  
373
-- | Tests string formatting for 'OpSubmitPriority'.
374
prop_OpSubmitPriority_string :: OpSubmitPriority -> Property
375
prop_OpSubmitPriority_string prio =
376
  parseSubmitPriority (fmtSubmitPriority prio) ==? Just prio
377

  
373 378
-- | Test 'ELogType' serialisation.
374 379
prop_ELogType_serialisation :: ELogType -> Property
375 380
prop_ELogType_serialisation = testSerialisation
......
416 421
  , 'case_JobId_BadTypes
417 422
  , 'prop_JobDependency_serialisation
418 423
  , 'prop_OpSubmitPriority_serialisation
424
  , 'prop_OpSubmitPriority_string
419 425
  , 'prop_ELogType_serialisation
420 426
  ]

Also available in: Unified diff