diff --git a/test/hs/Test/Ganeti/HTools/Types.hs b/test/hs/Test/Ganeti/HTools/Types.hs index 0cb187a21af933117f9bf5f35085adbcc32e4a01..da21725438e27ed0f7d53d352246f7eaa0ccbf05 100644 --- a/test/hs/Test/Ganeti/HTools/Types.hs +++ b/test/hs/Test/Ganeti/HTools/Types.hs @@ -7,7 +7,7 @@ {- -Copyright (C) 2009, 2010, 2011, 2012 Google Inc. +Copyright (C) 2009, 2010, 2011, 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 @@ -46,7 +46,7 @@ import Data.List (sort) import Test.Ganeti.TestHelper import Test.Ganeti.TestCommon import Test.Ganeti.TestHTools -import Test.Ganeti.Types () +import Test.Ganeti.Types (allDiskTemplates) import Ganeti.BasicTypes import qualified Ganeti.Constants as C @@ -56,10 +56,6 @@ import qualified Ganeti.HTools.Types as Types -- * Helpers --- | All disk templates (used later) -allDiskTemplates :: [Types.DiskTemplate] -allDiskTemplates = [minBound..maxBound] - -- * Arbitrary instance $(genArbitrary ''Types.FailMode) diff --git a/test/hs/Test/Ganeti/Types.hs b/test/hs/Test/Ganeti/Types.hs index 6246e6e0cde5fb2e1ae573dce758b7cf285c51f6..3eff2f0ce9a40e9e32646c55c2ce5fca04356d40 100644 --- a/test/hs/Test/Ganeti/Types.hs +++ b/test/hs/Test/Ganeti/Types.hs @@ -30,13 +30,14 @@ module Test.Ganeti.Types ( testTypes , AllocPolicy(..) , DiskTemplate(..) + , allDiskTemplates , InstanceStatus(..) , NonEmpty(..) , Hypervisor(..) , JobId(..) ) where -import Data.List (sort) +import Data.List (delete, sort) import Test.QuickCheck as QuickCheck hiding (Result) import Test.HUnit import qualified Text.JSON as J @@ -78,7 +79,22 @@ instance (Arbitrary a) => Arbitrary (Types.NonEmpty a) where $(genArbitrary ''AllocPolicy) -$(genArbitrary ''DiskTemplate) +-- | Valid disk templates (depending on configure options). +allDiskTemplates :: [DiskTemplate] +allDiskTemplates = + let all_vals = [minBound..maxBound]::[DiskTemplate] + sel1 = if C.enableFileStorage + then all_vals + else delete DTFile all_vals + sel2 = if C.enableSharedFileStorage + then sel1 + else delete DTSharedFile sel1 + in sel2 + +-- | Custom 'Arbitrary' instance for 'DiskTemplate', which needs to +-- handle the case of file storage being disabled at configure time. +instance Arbitrary DiskTemplate where + arbitrary = elements allDiskTemplates $(genArbitrary ''InstanceStatus) @@ -96,7 +112,18 @@ $(genArbitrary ''Hypervisor) $(genArbitrary ''OobCommand) -$(genArbitrary ''StorageType) +-- | Valid storage types. +allStorageTypes :: [StorageType] +allStorageTypes = + let all_vals = [minBound..maxBound]::[StorageType] + in if C.enableFileStorage + then all_vals + else delete StorageFile all_vals + +-- | Custom 'Arbitrary' instance for 'StorageType', which needs to +-- handle the case of file storage being disabled at configure time. +instance Arbitrary StorageType where + arbitrary = elements allStorageTypes $(genArbitrary ''NodeEvacMode)