summaryrefslogtreecommitdiff
path: root/testkiki
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2016-04-27 18:20:20 -0400
committerJames Crayne <jim.crayne@gmail.com>2016-04-27 18:23:50 -0400
commit1f008bcc12f883936b2e2caa57dee997e7e70bc3 (patch)
tree3240056c6dea6fdd9709af13e70f1457dcc5e92f /testkiki
parent6260d694a99348bc474b87b3d2184ead70cf3511 (diff)
refactoring
Diffstat (limited to 'testkiki')
-rw-r--r--testkiki/testkiki.hs23
1 files changed, 14 insertions, 9 deletions
diff --git a/testkiki/testkiki.hs b/testkiki/testkiki.hs
index 2a19889..64c1a6a 100644
--- a/testkiki/testkiki.hs
+++ b/testkiki/testkiki.hs
@@ -27,10 +27,14 @@ import Data.IORef
27import Crypto.Hash.SHA1 (hash) 27import Crypto.Hash.SHA1 (hash)
28import System.IO.Unsafe (unsafePerformIO) 28import System.IO.Unsafe (unsafePerformIO)
29import ProcessUtils 29import ProcessUtils
30import Data.Bool
30 31
31#if !MIN_VERSION_base(4,7,0) 32#if !MIN_VERSION_base(4,7,0)
32setEnv k v = System.Posix.Env.setEnv k v True 33setEnv k v = System.Posix.Env.setEnv k v True
33unsetEnv = System.Posix.Env.unsetEnv 34unsetEnv = System.Posix.Env.unsetEnv
35bool :: a -> a -> Bool -> a
36bool f _ False = f
37bool _ t True = t
34#endif 38#endif
35 39
36data TestKikiSettings = TKS 40data TestKikiSettings = TKS
@@ -257,9 +261,8 @@ doTests tkConfig = hspec $ do
257 261
258 -- **** cokiki tests ***** 262 -- **** cokiki tests *****
259 describe "cokiki ssh-client" $ do 263 describe "cokiki ssh-client" $ do
260 it "modifies system ssh configuration to respect /var/cache/kiki/ssh_known_hosts." $ do 264 it "modifies system ssh configuration to respect /var/cache/kiki/ssh_known_hosts." $
261 bDidInit3 <-readIORef didInit3 265 onlyIf didInit3 $ do
262 if not bDidInit3 then skipThisTest else do
263 let cfg' = appendpaths tkConfig "3" 266 let cfg' = appendpaths tkConfig "3"
264 home = chroot cfg' </> "root" 267 home = chroot cfg' </> "root"
265 gnuhome = home </> ".gnupg" 268 gnuhome = home </> ".gnupg"
@@ -290,9 +293,8 @@ doTests tkConfig = hspec $ do
290 (lost,gained,bChanged,(subStr0,subStr),compare mtime mtime0) `shouldBe` (1,1,True,(False,True),GT) 293 (lost,gained,bChanged,(subStr0,subStr),compare mtime mtime0) `shouldBe` (1,1,True,(False,True),GT)
291 294
292 describe "cokiki ssh-server" $ do 295 describe "cokiki ssh-server" $ do
293 it "modifies system ssh config to use /var/cache/kiki/ssh_host_rsa_key." $ do 296 it "modifies system ssh config to use /var/cache/kiki/ssh_host_rsa_key." $
294 bDidInit3 <-readIORef didInit3 297 onlyIf didInit3 $ do
295 if not bDidInit3 then skipThisTest else do
296 let cfg' = appendpaths tkConfig "3" 298 let cfg' = appendpaths tkConfig "3"
297 home = chroot cfg' </> "root" 299 home = chroot cfg' </> "root"
298 gnuhome = home </> ".gnupg" 300 gnuhome = home </> ".gnupg"
@@ -304,8 +306,7 @@ doTests tkConfig = hspec $ do
304 306
305 describe "cokiki strongswan" $ do 307 describe "cokiki strongswan" $ do
306 it "modifies /etc/ipsec.conf to include settings from /var/cache/kiki/ipsec.conf." $ do 308 it "modifies /etc/ipsec.conf to include settings from /var/cache/kiki/ipsec.conf." $ do
307 bDidInit3 <-readIORef didInit3 309 onlyIf didInit3 $ do
308 if not bDidInit3 then skipThisTest else do
309 let cfg' = appendpaths tkConfig "3" 310 let cfg' = appendpaths tkConfig "3"
310 home = chroot cfg' </> "root" 311 home = chroot cfg' </> "root"
311 gnuhome = home </> ".gnupg" 312 gnuhome = home </> ".gnupg"
@@ -316,6 +317,10 @@ doTests tkConfig = hspec $ do
316 pending 317 pending
317 318
318 where 319 where
320 onlyIf ref action = do
321 b <- readIORef ref
322 when b action
323
319 skipThisTest = pendingWith "SKIPPING due to prior failure." 324 skipThisTest = pendingWith "SKIPPING due to prior failure."
320 325
321 freshStdErrHandle tmpdir = openTempFile tmpdir "err.tmp" 326 freshStdErrHandle tmpdir = openTempFile tmpdir "err.tmp"
@@ -325,7 +330,7 @@ doTests tkConfig = hspec $ do
325 len <- (+1) . length <$> getCurrentDirectory 330 len <- (+1) . length <$> getCurrentDirectory
326 -- dump stderr here 331 -- dump stderr here
327 bracket (freshStdErrHandle dir) 332 bracket (freshStdErrHandle dir)
328 (\(_,h) -> hClose h) $ \(errfile,myStdErr) -> do 333 (\(_,h) -> hClose h) $ \(errfile,myStdErr) ->
329 flip catch (\(e::SomeException) -> (do 334 flip catch (\(e::SomeException) -> (do
330 b <- hIsOpen myStdErr 335 b <- hIsOpen myStdErr
331 x <- if b then do 336 x <- if b then do