etcd 1.0.4 → 1.0.5
raw patch · 3 files changed
+29/−1 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Network.Etcd: listDirectoryContentsRecursive :: Client -> Key -> IO [Node]
Files
- etcd.cabal +1/−1
- src/Network/Etcd.hs +17/−0
- test/Test.hs +11/−0
etcd.cabal view
@@ -1,5 +1,5 @@ name: etcd-version: 1.0.4+version: 1.0.5 license: OtherLicense license-file: UNLICENSE synopsis: Client for etcd, a highly-available key value store
src/Network/Etcd.hs view
@@ -30,6 +30,7 @@ -- * Directory operations , createDirectory , listDirectoryContents+ , listDirectoryContentsRecursive , removeDirectory , removeDirectoryRecursive ) where@@ -391,6 +392,22 @@ case _nodeNodes node of Nothing -> return [] Just children -> return children+++-- | Same as 'listDirectoryContents' but includes all descendant nodes. Note+-- that directory 'Node's will not contain their children.+listDirectoryContentsRecursive :: Client -> Key -> IO [Node]+listDirectoryContentsRecursive client key = do+ hr <- runRequest $ httpGET (keyUrl client key) recursiveParam+ case hr of+ Left _ -> return []+ Right res -> do+ let node = _resNode res+ flatten n = n { _nodeNodes = Nothing }+ : maybe [] (concatMap flatten) (_nodeNodes n)+ case _nodeNodes node of+ Nothing -> return []+ Just children -> return $ concatMap flatten children -- | Remove the directory at the given key. The directory MUST be empty,
test/Test.hs view
@@ -138,6 +138,17 @@ length nodes `shouldBe` 1 _nodeValue (head nodes) `shouldBe` (Just "value") + it "Listing a directory recursively" $ do+ (client, key) <- setup+ createDirectory client key Nothing+ createDirectory client (key <> "/one") Nothing+ set client (key <> "/one/two") "value" Nothing+ set client (key <> "/one/three") "value" Nothing+ nodes <- listDirectoryContentsRecursive client key+ length nodes `shouldBe` 3+ _nodeValue (head nodes) `shouldBe` Nothing+ _nodeValue (last nodes) `shouldBe` (Just "value")+ it "Deleting a directory recursively" $ do (client, key) <- setup createDirectory client key Nothing