module Test.Ganeti.Query.Network
( testQuery_Network
) where
import Ganeti.JSON
import Ganeti.Objects
import Ganeti.Query.Network
import Ganeti.Types
import Test.Ganeti.Objects
import Test.Ganeti.TestCommon
import Test.Ganeti.TestHelper
import Test.QuickCheck
import qualified Data.Map as Map
import Data.Maybe
instance Arbitrary ConfigData where
arbitrary = genEmptyCluster 0 >>= genConfigDataWithNetworks
prop_getGroupConnection :: NodeGroup -> Property
prop_getGroupConnection group =
let net_keys = (Map.keys . fromContainer . groupNetworks) group
in True ==? all
(\nk -> isJust (getGroupConnection nk group)) net_keys
prop_getGroupConnection_notFound :: NodeGroup -> String -> Property
prop_getGroupConnection_notFound group uuid =
let net_keys = (Map.keys . fromContainer . groupNetworks) group
in notElem uuid net_keys ==> isNothing (getGroupConnection uuid group)
prop_instIsConnected :: ConfigData -> Property
prop_instIsConnected cfg =
let nets = (fromContainer . configNetworks) cfg
net_keys = Map.keys nets
net_names = map (fromNonEmpty . networkName) (Map.elems nets)
in forAll (genInstWithNets net_names) $ \inst ->
True ==? all (\nk -> instIsConnected cfg nk inst) net_keys
prop_instIsConnected_notFound :: ConfigData -> String -> Property
prop_instIsConnected_notFound cfg network_uuid =
let nets = (fromContainer . configNetworks) cfg
net_keys = Map.keys nets
net_names = map (fromNonEmpty . networkName) (Map.elems nets)
in notElem network_uuid net_keys ==>
forAll (genInstWithNets net_names) $ \inst ->
not (instIsConnected cfg network_uuid inst)
testSuite "Query_Network"
[ 'prop_getGroupConnection
, 'prop_getGroupConnection_notFound
, 'prop_instIsConnected
, 'prop_instIsConnected_notFound
]