Commit 2d87bd0a authored by Iustin Pop's avatar Iustin Pop
Browse files

Split last two remaining tests from QC.hs



This makes QC.hs obsolete, but we will remove it in a later patch,
once we automatically build a file with all the imports (to ensure
correct coverage results).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent f3baf5ef
......@@ -446,6 +446,8 @@ HS_LIB_SRCS = \
htest/Test/Ganeti/HTools/Text.hs \
htest/Test/Ganeti/HTools/Types.hs \
htest/Test/Ganeti/HTools/Utils.hs \
htest/Test/Ganeti/JSON.hs \
htest/Test/Ganeti/Jobs.hs \
htest/Test/Ganeti/Luxi.hs \
htest/Test/Ganeti/Objects.hs \
htest/Test/Ganeti/OpCodes.hs \
......
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-| Unittests for ganeti-htools.
-}
{-
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
-}
module Test.Ganeti.JSON (testJSON) where
import Test.QuickCheck
import qualified Text.JSON as J
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
import qualified Ganeti.BasicTypes as BasicTypes
import qualified Ganeti.JSON as JSON
prop_JSON_toArray :: [Int] -> Property
prop_JSON_toArray intarr =
let arr = map J.showJSON intarr in
case JSON.toArray (J.JSArray arr) of
BasicTypes.Ok arr' -> arr ==? arr'
BasicTypes.Bad err -> failTest $ "Failed to parse array: " ++ err
prop_JSON_toArrayFail :: Int -> String -> Bool -> Property
prop_JSON_toArrayFail i s b =
-- poor man's instance Arbitrary JSValue
forAll (elements [J.showJSON i, J.showJSON s, J.showJSON b]) $ \item ->
case JSON.toArray item of
BasicTypes.Bad _ -> property True
BasicTypes.Ok result -> failTest $ "Unexpected parse, got " ++ show result
testSuite "JSON"
[ 'prop_JSON_toArray
, 'prop_JSON_toArrayFail
]
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-| Unittests for ganeti-htools.
-}
{-
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
-}
module Test.Ganeti.Jobs (testJobs) where
import Test.QuickCheck
import qualified Text.JSON as J
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
import qualified Ganeti.Jobs as Jobs
-- * Arbitrary instances
instance Arbitrary Jobs.OpStatus where
arbitrary = elements [minBound..maxBound]
instance Arbitrary Jobs.JobStatus where
arbitrary = elements [minBound..maxBound]
-- * Test cases
-- | Check that (queued) job\/opcode status serialization is idempotent.
prop_Jobs_OpStatus_serialization :: Jobs.OpStatus -> Property
prop_Jobs_OpStatus_serialization os =
case J.readJSON (J.showJSON os) of
J.Error e -> failTest $ "Cannot deserialise: " ++ e
J.Ok os' -> os ==? os'
prop_Jobs_JobStatus_serialization :: Jobs.JobStatus -> Property
prop_Jobs_JobStatus_serialization js =
case J.readJSON (J.showJSON js) of
J.Error e -> failTest $ "Cannot deserialise: " ++ e
J.Ok js' -> js ==? js'
testSuite "Jobs"
[ 'prop_Jobs_OpStatus_serialization
, 'prop_Jobs_JobStatus_serialization
]
......@@ -29,7 +29,7 @@ import Data.Monoid (mappend)
import Test.Framework
import System.Environment (getArgs)
import Ganeti.HTools.QC
import Ganeti.HTools.QC ()
import Test.Ganeti.Confd.Utils
import Test.Ganeti.HTools.CLI
import Test.Ganeti.HTools.Cluster
......@@ -42,6 +42,8 @@ import Test.Ganeti.HTools.Simu
import Test.Ganeti.HTools.Text
import Test.Ganeti.HTools.Types
import Test.Ganeti.HTools.Utils
import Test.Ganeti.Jobs
import Test.Ganeti.JSON
import Test.Ganeti.Luxi
import Test.Ganeti.Objects
import Test.Ganeti.OpCodes
......
......@@ -32,9 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-}
module Ganeti.HTools.QC
( testJobs
, testJSON
) where
() where
import qualified Test.HUnit as HUnit
import Test.QuickCheck
......@@ -100,57 +98,3 @@ import qualified Ganeti.HTools.Program.Hspace
import Test.Ganeti.TestHelper (testSuite)
import Test.Ganeti.TestCommon
-- * Helper functions
instance Arbitrary Jobs.OpStatus where
arbitrary = elements [minBound..maxBound]
instance Arbitrary Jobs.JobStatus where
arbitrary = elements [minBound..maxBound]
-- * Actual tests
-- ** Jobs tests
-- | Check that (queued) job\/opcode status serialization is idempotent.
prop_Jobs_OpStatus_serialization :: Jobs.OpStatus -> Property
prop_Jobs_OpStatus_serialization os =
case J.readJSON (J.showJSON os) of
J.Error e -> failTest $ "Cannot deserialise: " ++ e
J.Ok os' -> os ==? os'
prop_Jobs_JobStatus_serialization :: Jobs.JobStatus -> Property
prop_Jobs_JobStatus_serialization js =
case J.readJSON (J.showJSON js) of
J.Error e -> failTest $ "Cannot deserialise: " ++ e
J.Ok js' -> js ==? js'
testSuite "Jobs"
[ 'prop_Jobs_OpStatus_serialization
, 'prop_Jobs_JobStatus_serialization
]
-- * JSON tests
prop_JSON_toArray :: [Int] -> Property
prop_JSON_toArray intarr =
let arr = map J.showJSON intarr in
case JSON.toArray (J.JSArray arr) of
Types.Ok arr' -> arr ==? arr'
Types.Bad err -> failTest $ "Failed to parse array: " ++ err
prop_JSON_toArrayFail :: Int -> String -> Bool -> Property
prop_JSON_toArrayFail i s b =
-- poor man's instance Arbitrary JSValue
forAll (elements [J.showJSON i, J.showJSON s, J.showJSON b]) $ \item ->
case JSON.toArray item of
Types.Bad _ -> property True
Types.Ok result -> failTest $ "Unexpected parse, got " ++ show result
testSuite "JSON"
[ 'prop_JSON_toArray
, 'prop_JSON_toArrayFail
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment