From dc4b5c42b9f607bcbdcb1cb4fe72d2ad2ce065f5 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 26 Nov 2012 13:34:31 +0100
Subject: [PATCH] Add explicit test for wrong OpCode arbitrary instances

I've been bitten a couple of times with arbitrary opcodes working on
UTF-8 locale, but failing on buildbot (ASCII). So let's add an
explicit test that checks always (even with UTF-8) for correct
arbitrary values, showing explicitly which opcodes fail.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>
---
 htest/Test/Ganeti/OpCodes.hs | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/htest/Test/Ganeti/OpCodes.hs b/htest/Test/Ganeti/OpCodes.hs
index ab56f69d4..b2f6a7406 100644
--- a/htest/Test/Ganeti/OpCodes.hs
+++ b/htest/Test/Ganeti/OpCodes.hs
@@ -35,6 +35,8 @@ import qualified Test.HUnit as HUnit
 import Test.QuickCheck
 
 import Control.Applicative
+import Control.Monad
+import Data.Char
 import Data.List
 import qualified Data.Map as Map
 import qualified Text.JSON as J
@@ -441,6 +443,11 @@ case_py_compat = do
                              (arbitrary::Gen OpCodes.OpCode))
   let opcodes = head sample_opcodes
       serialized = J.encode opcodes
+  -- check for non-ASCII fields, usually due to 'arbitrary :: String'
+  mapM_ (\op -> when (any (not . isAscii) (J.encode op)) .
+                HUnit.assertFailure $
+                  "OpCode has non-ASCII fields: " ++ show op
+        ) opcodes
   py_stdout <-
      runPython "from ganeti import opcodes\n\
                \import sys\n\
-- 
GitLab