Commit 5c3ddba5 authored by Niklas Hambuechen's avatar Niklas Hambuechen Committed by Petr Pudlak

Tests: Extract Test.Ganeti.JQueue.Objects module

We want to reuse functions for it for a future 'Test.Ganeti.JQScheduler'.
Signed-off-by: default avatarNiklas Hambuechen <niklash@google.com>
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 038538c3
......@@ -163,6 +163,7 @@ HS_DIRS = \
test/hs/Test/Ganeti/HTools/Backend \
test/hs/Test/Ganeti/Hypervisor \
test/hs/Test/Ganeti/Hypervisor/Xen \
test/hs/Test/Ganeti/JQueue \
test/hs/Test/Ganeti/Locking \
test/hs/Test/Ganeti/Objects \
test/hs/Test/Ganeti/Query \
......@@ -941,6 +942,7 @@ HS_TEST_SRCS = \
test/hs/Test/Ganeti/JSON.hs \
test/hs/Test/Ganeti/Jobs.hs \
test/hs/Test/Ganeti/JQueue.hs \
test/hs/Test/Ganeti/JQueue/Objects.hs \
test/hs/Test/Ganeti/Kvmd.hs \
test/hs/Test/Ganeti/Luxi.hs \
test/hs/Test/Ganeti/Locking/Allocation.hs \
......
......@@ -27,7 +27,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Test.Ganeti.JQueue (testJQueue) where
import Control.Applicative
import Control.Monad (when)
import Data.Char (isAscii)
import Data.List (nub, sort)
......@@ -43,7 +42,6 @@ import Text.JSON
import Test.Ganeti.TestCommon
import Test.Ganeti.TestHelper
import Test.Ganeti.Types ()
import Test.Ganeti.OpCodes ()
import Ganeti.BasicTypes
import qualified Ganeti.Constants as C
......@@ -51,35 +49,11 @@ import Ganeti.JQueue
import Ganeti.OpCodes
import Ganeti.Path
import Ganeti.Types as Types
import Test.Ganeti.JQueue.Objects (justNoTs, genQueuedOpCode, emptyJob,
genJobId)
{-# ANN module "HLint: ignore Use camelCase" #-}
-- * Helpers
-- | noTimestamp in Just form.
justNoTs :: Maybe Timestamp
justNoTs = Just noTimestamp
-- | Generates a simple queued opcode.
genQueuedOpCode :: Gen QueuedOpCode
genQueuedOpCode =
QueuedOpCode <$> (ValidOpCode <$> arbitrary) <*>
arbitrary <*> pure JSNull <*> pure [] <*>
choose (C.opPrioLowest, C.opPrioHighest) <*>
pure justNoTs <*> pure justNoTs <*> pure justNoTs
-- | Generates an static, empty job.
emptyJob :: (Monad m) => m QueuedJob
emptyJob = do
jid0 <- makeJobId 0
return $ QueuedJob jid0 [] justNoTs justNoTs justNoTs Nothing Nothing
-- | Generates a job ID.
genJobId :: Gen JobId
genJobId = do
p <- arbitrary::Gen (Types.NonNegative Int)
makeJobId $ fromNonNegative p
-- * Test cases
-- | Tests default priority value.
......
{-| Unittests for 'Ganeti.JQueue.Objects'.
-}
{-
Copyright (C) 2012, 2013 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.JQueue.Objects
( justNoTs
, genQueuedOpCode
, emptyJob
, genJobId
) where
import Control.Applicative
import Test.QuickCheck as QuickCheck
import Text.JSON
import Test.Ganeti.Types ()
import Test.Ganeti.OpCodes ()
import qualified Ganeti.Constants as C
import Ganeti.JQueue
import Ganeti.Types as Types
-- | noTimestamp in Just form.
justNoTs :: Maybe Timestamp
justNoTs = Just noTimestamp
-- | Generates a simple queued opcode.
genQueuedOpCode :: Gen QueuedOpCode
genQueuedOpCode =
QueuedOpCode <$> (ValidOpCode <$> arbitrary) <*>
arbitrary <*> pure JSNull <*> pure [] <*>
choose (C.opPrioLowest, C.opPrioHighest) <*>
pure justNoTs <*> pure justNoTs <*> pure justNoTs
-- | Generates an static, empty job.
emptyJob :: (Monad m) => m QueuedJob
emptyJob = do
jid0 <- makeJobId 0
return $ QueuedJob jid0 [] justNoTs justNoTs justNoTs Nothing Nothing
-- | Generates a job ID.
genJobId :: Gen JobId
genJobId = do
p <- arbitrary::Gen (Types.NonNegative Int)
makeJobId $ fromNonNegative p
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