Revision a5b270c5

b/htest/Test/Ganeti/Utils.hs
37 37

  
38 38
import qualified Ganeti.JSON as JSON
39 39
import qualified Ganeti.HTools.Types as Types
40
import qualified Ganeti.Utils as Utils
40
import Ganeti.Utils
41 41

  
42 42
-- | Helper to generate a small string that doesn't contain commas.
43 43
genNonCommaString :: Gen String
......
51 51
prop_commaJoinSplit =
52 52
  forAll (choose (0, 20)) $ \llen ->
53 53
  forAll (vectorOf llen genNonCommaString `suchThat` (/=) [""]) $ \lst ->
54
  Utils.sepSplit ',' (Utils.commaJoin lst) ==? lst
54
  sepSplit ',' (commaJoin lst) ==? lst
55 55

  
56 56
-- | Split and join should always be idempotent.
57 57
prop_commaSplitJoin :: String -> Property
58 58
prop_commaSplitJoin s =
59
  Utils.commaJoin (Utils.sepSplit ',' s) ==? s
59
  commaJoin (sepSplit ',' s) ==? s
60 60

  
61 61
-- | fromObjWithDefault, we test using the Maybe monad and an integer
62 62
-- value.
......
71 71
-- | Test that functional if' behaves like the syntactic sugar if.
72 72
prop_if'if :: Bool -> Int -> Int -> Gen Prop
73 73
prop_if'if cnd a b =
74
  Utils.if' cnd a b ==? if cnd then a else b
74
  if' cnd a b ==? if cnd then a else b
75 75

  
76 76
-- | Test basic select functionality
77 77
prop_select :: Int      -- ^ Default result
......
79 79
            -> [Int]    -- ^ List of True values
80 80
            -> Gen Prop -- ^ Test result
81 81
prop_select def lst1 lst2 =
82
  Utils.select def (flist ++ tlist) ==? expectedresult
83
    where expectedresult = Utils.if' (null lst2) def (head lst2)
82
  select def (flist ++ tlist) ==? expectedresult
83
    where expectedresult = if' (null lst2) def (head lst2)
84 84
          flist = zip (repeat False) lst1
85 85
          tlist = zip (repeat True)  lst2
86 86

  
......
89 89
                   -> NonEmptyList Int -- ^ List of True values
90 90
                   -> Gen Prop         -- ^ Test result
91 91
prop_select_undefd lst1 (NonEmpty lst2) =
92
  Utils.select undefined (flist ++ tlist) ==? head lst2
92
  select undefined (flist ++ tlist) ==? head lst2
93 93
    where flist = zip (repeat False) lst1
94 94
          tlist = zip (repeat True)  lst2
95 95

  
......
98 98
                   -> NonEmptyList Int -- ^ List of True values
99 99
                   -> Gen Prop         -- ^ Test result
100 100
prop_select_undefv lst1 (NonEmpty lst2) =
101
  Utils.select undefined cndlist ==? head lst2
101
  select undefined cndlist ==? head lst2
102 102
    where flist = zip (repeat False) lst1
103 103
          tlist = zip (repeat True)  lst2
104 104
          cndlist = flist ++ tlist ++ [undefined]
105 105

  
106 106
prop_parseUnit :: NonNegative Int -> Property
107 107
prop_parseUnit (NonNegative n) =
108
  Utils.parseUnit (show n) ==? Types.Ok n .&&.
109
  Utils.parseUnit (show n ++ "m") ==? Types.Ok n .&&.
110
  Utils.parseUnit (show n ++ "M") ==? Types.Ok (truncate n_mb::Int) .&&.
111
  Utils.parseUnit (show n ++ "g") ==? Types.Ok (n*1024) .&&.
112
  Utils.parseUnit (show n ++ "G") ==? Types.Ok (truncate n_gb::Int) .&&.
113
  Utils.parseUnit (show n ++ "t") ==? Types.Ok (n*1048576) .&&.
114
  Utils.parseUnit (show n ++ "T") ==? Types.Ok (truncate n_tb::Int) .&&.
108
  parseUnit (show n) ==? Types.Ok n .&&.
109
  parseUnit (show n ++ "m") ==? Types.Ok n .&&.
110
  parseUnit (show n ++ "M") ==? Types.Ok (truncate n_mb::Int) .&&.
111
  parseUnit (show n ++ "g") ==? Types.Ok (n*1024) .&&.
112
  parseUnit (show n ++ "G") ==? Types.Ok (truncate n_gb::Int) .&&.
113
  parseUnit (show n ++ "t") ==? Types.Ok (n*1048576) .&&.
114
  parseUnit (show n ++ "T") ==? Types.Ok (truncate n_tb::Int) .&&.
115 115
  printTestCase "Internal error/overflow?"
116 116
    (n_mb >=0 && n_gb >= 0 && n_tb >= 0) .&&.
117
  property (Types.isBad (Utils.parseUnit (show n ++ "x")::Types.Result Int))
117
  property (Types.isBad (parseUnit (show n ++ "x")::Types.Result Int))
118 118
  where n_mb = (fromIntegral n::Rational) * 1000 * 1000 / 1024 / 1024
119 119
        n_gb = n_mb * 1000
120 120
        n_tb = n_gb * 1000

Also available in: Unified diff