From 50811e2c51a237ea4e24b2fd16fb0a34d548c077 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 25 Aug 2010 18:04:41 +0200 Subject: [PATCH] Add unittest for Node text serialization This checks that the Node text serialization and deserialization operations are idempotent when combined other. --- Ganeti/HTools/Node.hs | 4 ++-- Ganeti/HTools/QC.hs | 8 ++++++++ Ganeti/HTools/Text.hs | 1 + Ganeti/HTools/Types.hs | 4 ++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Ganeti/HTools/Node.hs b/Ganeti/HTools/Node.hs index cdb375db7..ece5e7b7c 100644 --- a/Ganeti/HTools/Node.hs +++ b/Ganeti/HTools/Node.hs @@ -6,7 +6,7 @@ {- -Copyright (C) 2009 Google Inc. +Copyright (C) 2009, 2010 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 @@ -119,7 +119,7 @@ data Node = Node , utilPool :: T.DynUtil -- ^ Total utilisation capacity , utilLoad :: T.DynUtil -- ^ Sum of instance utilisation , pTags :: TagMap -- ^ Map of primary instance tags and their count - } deriving (Show) + } deriving (Show, Eq) instance T.Element Node where nameOf = name diff --git a/Ganeti/HTools/QC.hs b/Ganeti/HTools/QC.hs index 28410d409..1f2a460c3 100644 --- a/Ganeti/HTools/QC.hs +++ b/Ganeti/HTools/QC.hs @@ -456,11 +456,19 @@ prop_Text_Load_Node name tm nm fm td fd tc fo = prop_Text_Load_NodeFail fields = length fields /= 8 ==> isNothing $ Text.loadNode fields +prop_Text_NodeLSIdempotent node = + (Text.loadNode . + Utils.sepSplit '|' . Text.serializeNode) n == + Just (Node.name n, n) + -- override failN1 to what loadNode returns by default + where n = node { Node.failN1 = True, Node.offline = False } + testText = [ run prop_Text_Load_Instance , run prop_Text_Load_InstanceFail , run prop_Text_Load_Node , run prop_Text_Load_NodeFail + , run prop_Text_NodeLSIdempotent ] -- Node tests diff --git a/Ganeti/HTools/Text.hs b/Ganeti/HTools/Text.hs index fcccbd8f2..55d8f42e1 100644 --- a/Ganeti/HTools/Text.hs +++ b/Ganeti/HTools/Text.hs @@ -32,6 +32,7 @@ module Ganeti.HTools.Text , loadInst , loadNode , serializeInstances + , serializeNode , serializeNodes ) where diff --git a/Ganeti/HTools/Types.hs b/Ganeti/HTools/Types.hs index dbdac0594..7cab64113 100644 --- a/Ganeti/HTools/Types.hs +++ b/Ganeti/HTools/Types.hs @@ -4,7 +4,7 @@ {- -Copyright (C) 2009 Google Inc. +Copyright (C) 2009, 2010 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 @@ -83,7 +83,7 @@ data DynUtil = DynUtil , memWeight :: Weight -- ^ Standardised memory load , dskWeight :: Weight -- ^ Standardised disk I\/O usage , netWeight :: Weight -- ^ Standardised network usage - } deriving (Show) + } deriving (Show, Eq) -- | Initial empty utilisation zeroUtil :: DynUtil -- GitLab