aboutsummaryrefslogtreecommitdiff
path: root/Command/TestRemote.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-08-10 14:52:58 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-08-10 15:02:59 -0400
commitc88874a89db54402dbf6bdd56f6d0306f4303e53 (patch)
tree35b27c254a39b0674142b7cf313492a705e4874b /Command/TestRemote.hs
parent425730f03a68cfa6a0e43a88c83f3470d8724627 (diff)
testremote: Add testing of behavior when remote is not available
Added a mkUnavailable method, which a Remote can use to generate a version of itself that is not available. Implemented for several, but not yet all remotes. This allows testing that checkPresent properly throws an exceptions when it cannot check if a key is present or not. It also allows testing that the other methods don't throw exceptions in these circumstances. This immediately found several bugs, which this commit also fixes! * git remotes using ssh accidentially had checkPresent return an exception, rather than throwing it * The chunking code accidentially returned False rather than propigating an exception when there were no chunks and checkPresent threw an exception for the non-chunked key. This commit was sponsored by Carlo Matteo Capocasa.
Diffstat (limited to 'Command/TestRemote.hs')
-rw-r--r--Command/TestRemote.hs35
1 files changed, 30 insertions, 5 deletions
diff --git a/Command/TestRemote.hs b/Command/TestRemote.hs
index cb36b66ba..3e1933d21 100644
--- a/Command/TestRemote.hs
+++ b/Command/TestRemote.hs
@@ -62,13 +62,16 @@ start basesz ws = do
ks <- mapM randKey (keySizes basesz fast)
rs <- catMaybes <$> mapM (adjustChunkSize r) (chunkSizes basesz fast)
rs' <- concat <$> mapM encryptionVariants rs
- next $ perform rs' ks
+ unavailrs <- catMaybes <$> mapM Remote.mkUnavailable [r]
+ next $ perform rs' unavailrs ks
-perform :: [Remote] -> [Key] -> CommandPerform
-perform rs ks = do
+perform :: [Remote] -> [Remote] -> [Key] -> CommandPerform
+perform rs unavailrs ks = do
st <- Annex.getState id
- let tests = testGroup "Remote Tests" $
- [ testGroup (desc r k) (test st r k) | k <- ks, r <- rs ]
+ let tests = testGroup "Remote Tests" $ concat
+ [ [ testGroup "unavailable remote" (testUnavailable st r (Prelude.head ks)) | r <- unavailrs ]
+ , [ testGroup (desc r k) (test st r k) | k <- ks, r <- rs ]
+ ]
ok <- case tryIngredients [consoleTestReporter] mempty tests of
Nothing -> error "No tests found!?"
Just act -> liftIO act
@@ -155,6 +158,28 @@ test st r k =
store = Remote.storeKey r k Nothing nullMeterUpdate
remove = Remote.removeKey r k
+testUnavailable :: Annex.AnnexState -> Remote -> Key -> [TestTree]
+testUnavailable st r k =
+ [ check (== Right False) "removeKey" $
+ Remote.removeKey r k
+ , check (== Right False) "storeKey" $
+ Remote.storeKey r k Nothing nullMeterUpdate
+ , check (`notElem` [Right True, Right False]) "checkPresent" $
+ Remote.checkPresent r k
+ , check (== Right False) "retrieveKeyFile" $
+ getViaTmp k $ \dest ->
+ Remote.retrieveKeyFile r k Nothing dest nullMeterUpdate
+ , check (== Right False) "retrieveKeyFileCheap" $
+ getViaTmp k $ \dest ->
+ Remote.retrieveKeyFileCheap r k dest
+ ]
+ where
+ check checkval desc a = testCase desc $ do
+ v <- Annex.eval st $ do
+ Annex.setOutput QuietOutput
+ either (Left . show) Right <$> tryNonAsync a
+ checkval v @? ("(got: " ++ show v ++ ")")
+
cleanup :: [Remote] -> [Key] -> Bool -> CommandCleanup
cleanup rs ks ok = do
forM_ rs $ \r -> forM_ ks (Remote.removeKey r)