syncthing-hs 0.1.0.0 → 0.1.1.0
raw patch · 17 files changed
+882/−78 lines, 17 filesdep +syncthing-hsPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: syncthing-hs
API changes (from Hackage documentation)
- Network.Syncthing: Address :: Addr -> AddressType
- Network.Syncthing: CacheEntry :: Addr -> Maybe UTCTime -> CacheEntry
- Network.Syncthing: Cleaning :: ModelState
- Network.Syncthing: Config :: Int -> [FolderConfig] -> [DeviceConfig] -> GuiConfig -> OptionsConfig -> Config
- Network.Syncthing: Connection :: Maybe UTCTime -> Integer -> Integer -> Addr -> Text -> Connection
- Network.Syncthing: DeviceConfig :: Device -> Text -> [AddressType] -> Bool -> Text -> Bool -> DeviceConfig
- Network.Syncthing: Dir :: Map Text DirTree -> DirTree
- Network.Syncthing: Dynamic :: AddressType
- Network.Syncthing: Error :: Maybe UTCTime -> Text -> Error
- Network.Syncthing: File :: Integer -> Integer -> DirTree
- Network.Syncthing: FolderConfig :: FolderName -> Path -> [Device] -> Bool -> Int -> Bool -> VersioningConfig -> Bool -> Int -> Int -> Text -> FolderConfig
- Network.Syncthing: GuiConfig :: Bool -> Maybe Text -> Addr -> Text -> Text -> Bool -> GuiConfig
- Network.Syncthing: Idle :: ModelState
- Network.Syncthing: Ignore :: Maybe [Text] -> Maybe [Text] -> Ignore
- Network.Syncthing: Model :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Maybe ModelState -> Maybe UTCTime -> Maybe Text -> Int -> Model
- Network.Syncthing: Need :: [Progress] -> [Text] -> [Text] -> Need
- Network.Syncthing: OptionsConfig :: [Addr] -> [Text] -> Bool -> Bool -> Int -> Text -> Int -> Int -> Int -> Bool -> Bool -> Int -> Int -> Int -> Text -> Bool -> Int -> Int -> Bool -> Int -> Bool -> OptionsConfig
- Network.Syncthing: OtherSystemMsg :: Text -> SystemMsg
- Network.Syncthing: Progress :: Text -> Int -> Integer -> Int -> Int -> Int -> Integer -> Progress
- Network.Syncthing: ResettingFolders :: SystemMsg
- Network.Syncthing: Restarting :: SystemMsg
- Network.Syncthing: Scanning :: ModelState
- Network.Syncthing: ShuttingDown :: SystemMsg
- Network.Syncthing: Syncing :: ModelState
- Network.Syncthing: System :: Integer -> Double -> Maybe (Map Server Bool) -> Int -> Text -> Integer -> System
- Network.Syncthing: Upgrade :: Text -> Bool -> Text -> Upgrade
- Network.Syncthing: Version :: Text -> Text -> Text -> Text -> Version
- Network.Syncthing: VersioningConfig :: Text -> Map Text Text -> VersioningConfig
- Network.Syncthing: data AddressType
- Network.Syncthing: data CacheEntry
- Network.Syncthing: data Config
- Network.Syncthing: data Connection
- Network.Syncthing: data DeviceConfig
- Network.Syncthing: data DirTree
- Network.Syncthing: data Error
- Network.Syncthing: data FolderConfig
- Network.Syncthing: data GuiConfig
- Network.Syncthing: data Ignore
- Network.Syncthing: data Model
- Network.Syncthing: data ModelState
- Network.Syncthing: data Need
- Network.Syncthing: data OptionsConfig
- Network.Syncthing: data Progress
- Network.Syncthing: data System
- Network.Syncthing: data SystemMsg
- Network.Syncthing: data Upgrade
- Network.Syncthing: data Version
- Network.Syncthing: data VersioningConfig
- Network.Syncthing: encodeAddr :: Addr -> Server
- Network.Syncthing: fromUTC :: UTCTime -> String
- Network.Syncthing: getAddr :: CacheEntry -> Addr
- Network.Syncthing: getAddress :: Connection -> Addr
- Network.Syncthing: getAddresses :: DeviceConfig -> [AddressType]
- Network.Syncthing: getAlloc :: System -> Integer
- Network.Syncthing: getApiKey :: GuiConfig -> Maybe Text
- Network.Syncthing: getArch :: Version -> Text
- Network.Syncthing: getAt :: Connection -> Maybe UTCTime
- Network.Syncthing: getAutoUpgradeIntervalH :: OptionsConfig -> Int
- Network.Syncthing: getCacheIgnoredFiles :: OptionsConfig -> Bool
- Network.Syncthing: getCertName :: DeviceConfig -> Text
- Network.Syncthing: getClientVersion :: Connection -> Text
- Network.Syncthing: getCompression :: DeviceConfig -> Bool
- Network.Syncthing: getConfigVersion :: Config -> Int
- Network.Syncthing: getCopiers :: FolderConfig -> Int
- Network.Syncthing: getCpuPercent :: System -> Double
- Network.Syncthing: getDevice :: DeviceConfig -> Device
- Network.Syncthing: getDeviceConfigs :: Config -> [DeviceConfig]
- Network.Syncthing: getDeviceName :: DeviceConfig -> Text
- Network.Syncthing: getDirContents :: DirTree -> Map Text DirTree
- Network.Syncthing: getEnabled :: GuiConfig -> Bool
- Network.Syncthing: getExtAnnounceOK :: System -> Maybe (Map Server Bool)
- Network.Syncthing: getFileSize :: DirTree -> Integer
- Network.Syncthing: getFlags :: Progress -> Int
- Network.Syncthing: getFolderConfigs :: Config -> [FolderConfig]
- Network.Syncthing: getFolderDevices :: FolderConfig -> [Device]
- Network.Syncthing: getFolderInvalid :: FolderConfig -> Text
- Network.Syncthing: getGlobalAnnEnabled :: OptionsConfig -> Bool
- Network.Syncthing: getGlobalAnnServers :: OptionsConfig -> [Text]
- Network.Syncthing: getGlobalBytes :: Model -> Integer
- Network.Syncthing: getGlobalDeleted :: Model -> Integer
- Network.Syncthing: getGlobalFiles :: Model -> Integer
- Network.Syncthing: getGoRoutines :: System -> Int
- Network.Syncthing: getGuiAddress :: GuiConfig -> Addr
- Network.Syncthing: getGuiConfig :: Config -> GuiConfig
- Network.Syncthing: getId :: FolderConfig -> FolderName
- Network.Syncthing: getIgnorePerms :: FolderConfig -> Bool
- Network.Syncthing: getIgnores :: Ignore -> Maybe [Text]
- Network.Syncthing: getInBytesTotal :: Connection -> Integer
- Network.Syncthing: getInSyncBytes :: Model -> Integer
- Network.Syncthing: getInSyncFiles :: Model -> Integer
- Network.Syncthing: getIntroducer :: DeviceConfig -> Bool
- Network.Syncthing: getInvalid :: Model -> Maybe Text
- Network.Syncthing: getKeepTemporariesH :: OptionsConfig -> Int
- Network.Syncthing: getLatest :: Upgrade -> Text
- Network.Syncthing: getLenientMtimes :: FolderConfig -> Bool
- Network.Syncthing: getListenAddress :: OptionsConfig -> [Addr]
- Network.Syncthing: getLocalAnnEnabled :: OptionsConfig -> Bool
- Network.Syncthing: getLocalAnnMCAddr :: OptionsConfig -> Text
- Network.Syncthing: getLocalAnnPort :: OptionsConfig -> Int
- Network.Syncthing: getLocalBytes :: Model -> Integer
- Network.Syncthing: getLocalDeleted :: Model -> Integer
- Network.Syncthing: getLocalFiles :: Model -> Integer
- Network.Syncthing: getLocalVersion :: Progress -> Int
- Network.Syncthing: getLongVersion :: Version -> Text
- Network.Syncthing: getMaxRecvKbps :: OptionsConfig -> Int
- Network.Syncthing: getMaxSendKbps :: OptionsConfig -> Int
- Network.Syncthing: getModTime :: DirTree -> Integer
- Network.Syncthing: getModelVersion :: Model -> Int
- Network.Syncthing: getModified :: Progress -> Integer
- Network.Syncthing: getMsg :: Error -> Text
- Network.Syncthing: getMyId :: System -> Text
- Network.Syncthing: getName :: Progress -> Text
- Network.Syncthing: getNeedBytes :: Model -> Integer
- Network.Syncthing: getNeedFiles :: Model -> Integer
- Network.Syncthing: getNewer :: Upgrade -> Bool
- Network.Syncthing: getNumBlocks :: Progress -> Int
- Network.Syncthing: getOptionsConfig :: Config -> OptionsConfig
- Network.Syncthing: getOs :: Version -> Text
- Network.Syncthing: getOutBytesTotal :: Connection -> Integer
- Network.Syncthing: getParams :: VersioningConfig -> Map Text Text
- Network.Syncthing: getPassword :: GuiConfig -> Text
- Network.Syncthing: getPath :: FolderConfig -> Path
- Network.Syncthing: getPatterns :: Ignore -> Maybe [Text]
- Network.Syncthing: getProgress :: Need -> [Progress]
- Network.Syncthing: getProgressUpdateIntervalS :: OptionsConfig -> Int
- Network.Syncthing: getProgressVersion :: Progress -> Int
- Network.Syncthing: getPullers :: FolderConfig -> Int
- Network.Syncthing: getQueued :: Need -> [Text]
- Network.Syncthing: getReadOnly :: FolderConfig -> Bool
- Network.Syncthing: getReconnectIntervalS :: OptionsConfig -> Int
- Network.Syncthing: getRescanIntervalS :: FolderConfig -> Int
- Network.Syncthing: getRest :: Need -> [Text]
- Network.Syncthing: getRestartOnWakeup :: OptionsConfig -> Bool
- Network.Syncthing: getRunning :: Upgrade -> Text
- Network.Syncthing: getSeen :: CacheEntry -> Maybe UTCTime
- Network.Syncthing: getSize :: Progress -> Integer
- Network.Syncthing: getStartBrowser :: OptionsConfig -> Bool
- Network.Syncthing: getState :: Model -> Maybe ModelState
- Network.Syncthing: getStateChanged :: Model -> Maybe UTCTime
- Network.Syncthing: getSymlinksEnabled :: OptionsConfig -> Bool
- Network.Syncthing: getSys :: System -> Integer
- Network.Syncthing: getTime :: Error -> Maybe UTCTime
- Network.Syncthing: getType :: VersioningConfig -> Text
- Network.Syncthing: getUPnPEnabled :: OptionsConfig -> Bool
- Network.Syncthing: getUPnPLease :: OptionsConfig -> Int
- Network.Syncthing: getUPnPRenewal :: OptionsConfig -> Int
- Network.Syncthing: getURAccepted :: OptionsConfig -> Int
- Network.Syncthing: getURUniqueID :: OptionsConfig -> Text
- Network.Syncthing: getUseTLS :: GuiConfig -> Bool
- Network.Syncthing: getUser :: GuiConfig -> Text
- Network.Syncthing: getVersion :: Version -> Text
- Network.Syncthing: getVersioning :: FolderConfig -> VersioningConfig
- Network.Syncthing: parseAddr :: Server -> Addr
- Network.Syncthing: toUTC :: String -> Maybe UTCTime
- Network.Syncthing: type Addr = (Host, Maybe Port)
- Network.Syncthing: type Device = Text
- Network.Syncthing: type FolderName = Text
- Network.Syncthing: type Host = Text
- Network.Syncthing: type Path = Text
- Network.Syncthing: type Port = Int
- Network.Syncthing: type Server = Text
+ Network.Syncthing.Internal: encodeAddr :: Addr -> Server
+ Network.Syncthing.Internal: fromUTC :: UTCTime -> String
+ Network.Syncthing.Internal: parseAddr :: Server -> Addr
+ Network.Syncthing.Internal: toUTC :: String -> Maybe UTCTime
+ Network.Syncthing.Types: Address :: Addr -> AddressType
+ Network.Syncthing.Types: CacheEntry :: Addr -> Maybe UTCTime -> CacheEntry
+ Network.Syncthing.Types: Cleaning :: ModelState
+ Network.Syncthing.Types: Config :: Int -> [FolderConfig] -> [DeviceConfig] -> GuiConfig -> OptionsConfig -> Config
+ Network.Syncthing.Types: Connection :: Maybe UTCTime -> Integer -> Integer -> Addr -> Text -> Connection
+ Network.Syncthing.Types: DeviceConfig :: Device -> Text -> [AddressType] -> Bool -> Text -> Bool -> DeviceConfig
+ Network.Syncthing.Types: Dir :: Map Text DirTree -> DirTree
+ Network.Syncthing.Types: Dynamic :: AddressType
+ Network.Syncthing.Types: Error :: Maybe UTCTime -> Text -> Error
+ Network.Syncthing.Types: File :: Integer -> Integer -> DirTree
+ Network.Syncthing.Types: FolderConfig :: FolderName -> Path -> [Device] -> Bool -> Int -> Bool -> VersioningConfig -> Bool -> Int -> Int -> Text -> FolderConfig
+ Network.Syncthing.Types: GuiConfig :: Bool -> Maybe Text -> Addr -> Text -> Text -> Bool -> GuiConfig
+ Network.Syncthing.Types: Idle :: ModelState
+ Network.Syncthing.Types: Ignore :: Maybe [Text] -> Maybe [Text] -> Ignore
+ Network.Syncthing.Types: Model :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Maybe ModelState -> Maybe UTCTime -> Maybe Text -> Int -> Model
+ Network.Syncthing.Types: Need :: [Progress] -> [Text] -> [Text] -> Need
+ Network.Syncthing.Types: OptionsConfig :: [Addr] -> [Text] -> Bool -> Bool -> Int -> Text -> Int -> Int -> Int -> Bool -> Bool -> Int -> Int -> Int -> Text -> Bool -> Int -> Int -> Bool -> Int -> Bool -> OptionsConfig
+ Network.Syncthing.Types: OtherSystemMsg :: Text -> SystemMsg
+ Network.Syncthing.Types: Progress :: Text -> Int -> Integer -> Int -> Int -> Int -> Integer -> Progress
+ Network.Syncthing.Types: ResettingFolders :: SystemMsg
+ Network.Syncthing.Types: Restarting :: SystemMsg
+ Network.Syncthing.Types: Scanning :: ModelState
+ Network.Syncthing.Types: ShuttingDown :: SystemMsg
+ Network.Syncthing.Types: Syncing :: ModelState
+ Network.Syncthing.Types: System :: Integer -> Double -> Maybe (Map Server Bool) -> Int -> Text -> Integer -> System
+ Network.Syncthing.Types: Upgrade :: Text -> Bool -> Text -> Upgrade
+ Network.Syncthing.Types: Version :: Text -> Text -> Text -> Text -> Version
+ Network.Syncthing.Types: VersioningConfig :: Text -> Map Text Text -> VersioningConfig
+ Network.Syncthing.Types: data AddressType
+ Network.Syncthing.Types: data CacheEntry
+ Network.Syncthing.Types: data Config
+ Network.Syncthing.Types: data Connection
+ Network.Syncthing.Types: data DeviceConfig
+ Network.Syncthing.Types: data DirTree
+ Network.Syncthing.Types: data Error
+ Network.Syncthing.Types: data FolderConfig
+ Network.Syncthing.Types: data GuiConfig
+ Network.Syncthing.Types: data Ignore
+ Network.Syncthing.Types: data Model
+ Network.Syncthing.Types: data ModelState
+ Network.Syncthing.Types: data Need
+ Network.Syncthing.Types: data OptionsConfig
+ Network.Syncthing.Types: data Progress
+ Network.Syncthing.Types: data System
+ Network.Syncthing.Types: data SystemMsg
+ Network.Syncthing.Types: data Upgrade
+ Network.Syncthing.Types: data Version
+ Network.Syncthing.Types: data VersioningConfig
+ Network.Syncthing.Types: getAddr :: CacheEntry -> Addr
+ Network.Syncthing.Types: getAddress :: Connection -> Addr
+ Network.Syncthing.Types: getAddresses :: DeviceConfig -> [AddressType]
+ Network.Syncthing.Types: getAlloc :: System -> Integer
+ Network.Syncthing.Types: getApiKey :: GuiConfig -> Maybe Text
+ Network.Syncthing.Types: getArch :: Version -> Text
+ Network.Syncthing.Types: getAt :: Connection -> Maybe UTCTime
+ Network.Syncthing.Types: getAutoUpgradeIntervalH :: OptionsConfig -> Int
+ Network.Syncthing.Types: getCacheIgnoredFiles :: OptionsConfig -> Bool
+ Network.Syncthing.Types: getCertName :: DeviceConfig -> Text
+ Network.Syncthing.Types: getClientVersion :: Connection -> Text
+ Network.Syncthing.Types: getCompression :: DeviceConfig -> Bool
+ Network.Syncthing.Types: getConfigVersion :: Config -> Int
+ Network.Syncthing.Types: getCopiers :: FolderConfig -> Int
+ Network.Syncthing.Types: getCpuPercent :: System -> Double
+ Network.Syncthing.Types: getDevice :: DeviceConfig -> Device
+ Network.Syncthing.Types: getDeviceConfigs :: Config -> [DeviceConfig]
+ Network.Syncthing.Types: getDeviceName :: DeviceConfig -> Text
+ Network.Syncthing.Types: getDirContents :: DirTree -> Map Text DirTree
+ Network.Syncthing.Types: getEnabled :: GuiConfig -> Bool
+ Network.Syncthing.Types: getExtAnnounceOK :: System -> Maybe (Map Server Bool)
+ Network.Syncthing.Types: getFileSize :: DirTree -> Integer
+ Network.Syncthing.Types: getFlags :: Progress -> Int
+ Network.Syncthing.Types: getFolderConfigs :: Config -> [FolderConfig]
+ Network.Syncthing.Types: getFolderDevices :: FolderConfig -> [Device]
+ Network.Syncthing.Types: getFolderInvalid :: FolderConfig -> Text
+ Network.Syncthing.Types: getGlobalAnnEnabled :: OptionsConfig -> Bool
+ Network.Syncthing.Types: getGlobalAnnServers :: OptionsConfig -> [Text]
+ Network.Syncthing.Types: getGlobalBytes :: Model -> Integer
+ Network.Syncthing.Types: getGlobalDeleted :: Model -> Integer
+ Network.Syncthing.Types: getGlobalFiles :: Model -> Integer
+ Network.Syncthing.Types: getGoRoutines :: System -> Int
+ Network.Syncthing.Types: getGuiAddress :: GuiConfig -> Addr
+ Network.Syncthing.Types: getGuiConfig :: Config -> GuiConfig
+ Network.Syncthing.Types: getId :: FolderConfig -> FolderName
+ Network.Syncthing.Types: getIgnorePerms :: FolderConfig -> Bool
+ Network.Syncthing.Types: getIgnores :: Ignore -> Maybe [Text]
+ Network.Syncthing.Types: getInBytesTotal :: Connection -> Integer
+ Network.Syncthing.Types: getInSyncBytes :: Model -> Integer
+ Network.Syncthing.Types: getInSyncFiles :: Model -> Integer
+ Network.Syncthing.Types: getIntroducer :: DeviceConfig -> Bool
+ Network.Syncthing.Types: getInvalid :: Model -> Maybe Text
+ Network.Syncthing.Types: getKeepTemporariesH :: OptionsConfig -> Int
+ Network.Syncthing.Types: getLatest :: Upgrade -> Text
+ Network.Syncthing.Types: getLenientMtimes :: FolderConfig -> Bool
+ Network.Syncthing.Types: getListenAddress :: OptionsConfig -> [Addr]
+ Network.Syncthing.Types: getLocalAnnEnabled :: OptionsConfig -> Bool
+ Network.Syncthing.Types: getLocalAnnMCAddr :: OptionsConfig -> Text
+ Network.Syncthing.Types: getLocalAnnPort :: OptionsConfig -> Int
+ Network.Syncthing.Types: getLocalBytes :: Model -> Integer
+ Network.Syncthing.Types: getLocalDeleted :: Model -> Integer
+ Network.Syncthing.Types: getLocalFiles :: Model -> Integer
+ Network.Syncthing.Types: getLocalVersion :: Progress -> Int
+ Network.Syncthing.Types: getLongVersion :: Version -> Text
+ Network.Syncthing.Types: getMaxRecvKbps :: OptionsConfig -> Int
+ Network.Syncthing.Types: getMaxSendKbps :: OptionsConfig -> Int
+ Network.Syncthing.Types: getModTime :: DirTree -> Integer
+ Network.Syncthing.Types: getModelVersion :: Model -> Int
+ Network.Syncthing.Types: getModified :: Progress -> Integer
+ Network.Syncthing.Types: getMsg :: Error -> Text
+ Network.Syncthing.Types: getMyId :: System -> Text
+ Network.Syncthing.Types: getName :: Progress -> Text
+ Network.Syncthing.Types: getNeedBytes :: Model -> Integer
+ Network.Syncthing.Types: getNeedFiles :: Model -> Integer
+ Network.Syncthing.Types: getNewer :: Upgrade -> Bool
+ Network.Syncthing.Types: getNumBlocks :: Progress -> Int
+ Network.Syncthing.Types: getOptionsConfig :: Config -> OptionsConfig
+ Network.Syncthing.Types: getOs :: Version -> Text
+ Network.Syncthing.Types: getOutBytesTotal :: Connection -> Integer
+ Network.Syncthing.Types: getParams :: VersioningConfig -> Map Text Text
+ Network.Syncthing.Types: getPassword :: GuiConfig -> Text
+ Network.Syncthing.Types: getPath :: FolderConfig -> Path
+ Network.Syncthing.Types: getPatterns :: Ignore -> Maybe [Text]
+ Network.Syncthing.Types: getProgress :: Need -> [Progress]
+ Network.Syncthing.Types: getProgressUpdateIntervalS :: OptionsConfig -> Int
+ Network.Syncthing.Types: getProgressVersion :: Progress -> Int
+ Network.Syncthing.Types: getPullers :: FolderConfig -> Int
+ Network.Syncthing.Types: getQueued :: Need -> [Text]
+ Network.Syncthing.Types: getReadOnly :: FolderConfig -> Bool
+ Network.Syncthing.Types: getReconnectIntervalS :: OptionsConfig -> Int
+ Network.Syncthing.Types: getRescanIntervalS :: FolderConfig -> Int
+ Network.Syncthing.Types: getRest :: Need -> [Text]
+ Network.Syncthing.Types: getRestartOnWakeup :: OptionsConfig -> Bool
+ Network.Syncthing.Types: getRunning :: Upgrade -> Text
+ Network.Syncthing.Types: getSeen :: CacheEntry -> Maybe UTCTime
+ Network.Syncthing.Types: getSize :: Progress -> Integer
+ Network.Syncthing.Types: getStartBrowser :: OptionsConfig -> Bool
+ Network.Syncthing.Types: getState :: Model -> Maybe ModelState
+ Network.Syncthing.Types: getStateChanged :: Model -> Maybe UTCTime
+ Network.Syncthing.Types: getSymlinksEnabled :: OptionsConfig -> Bool
+ Network.Syncthing.Types: getSys :: System -> Integer
+ Network.Syncthing.Types: getTime :: Error -> Maybe UTCTime
+ Network.Syncthing.Types: getType :: VersioningConfig -> Text
+ Network.Syncthing.Types: getUPnPEnabled :: OptionsConfig -> Bool
+ Network.Syncthing.Types: getUPnPLease :: OptionsConfig -> Int
+ Network.Syncthing.Types: getUPnPRenewal :: OptionsConfig -> Int
+ Network.Syncthing.Types: getURAccepted :: OptionsConfig -> Int
+ Network.Syncthing.Types: getURUniqueID :: OptionsConfig -> Text
+ Network.Syncthing.Types: getUseTLS :: GuiConfig -> Bool
+ Network.Syncthing.Types: getUser :: GuiConfig -> Text
+ Network.Syncthing.Types: getVersion :: Version -> Text
+ Network.Syncthing.Types: getVersioning :: FolderConfig -> VersioningConfig
+ Network.Syncthing.Types: type Addr = (Host, Maybe Port)
+ Network.Syncthing.Types: type Device = Text
+ Network.Syncthing.Types: type FolderName = Text
+ Network.Syncthing.Types: type Host = Text
+ Network.Syncthing.Types: type Path = Text
+ Network.Syncthing.Types: type Port = Int
+ Network.Syncthing.Types: type Server = Text
+ Network.Syncthing.Utils: encodeAddr :: Addr -> Server
+ Network.Syncthing.Utils: fromUTC :: UTCTime -> String
+ Network.Syncthing.Utils: parseAddr :: Server -> Addr
+ Network.Syncthing.Utils: toUTC :: String -> Maybe UTCTime
Files
- Network/Syncthing.hs +10/−37
- Network/Syncthing/Get.hs +1/−1
- Network/Syncthing/Internal.hs +6/−0
- Network/Syncthing/Internal/Types.hs +26/−0
- Network/Syncthing/Post.hs +1/−1
- Network/Syncthing/Types.hs +44/−19
- Network/Syncthing/Types/Common.hs +0/−5
- Network/Syncthing/Utils.hs +18/−0
- README.md +1/−0
- changelog.md +10/−0
- syncthing-hs.cabal +17/−15
- tests/Properties/ErrorProperties.hs +51/−0
- tests/Properties/JsonArbitrary.hs +149/−0
- tests/Properties/JsonInstances.hs +158/−0
- tests/Properties/JsonProperties.hs +52/−0
- tests/UnitTests/Errors.hs +53/−0
- tests/UnitTests/Requests.hs +285/−0
Network/Syncthing.hs view
@@ -48,17 +48,8 @@ module Network.Syncthing (- -- * Types- Server- , Device- , FolderName- , Path- , Host- , Port- , Addr- -- * The Syncthing Monad- , SyncResult+ SyncResult , SyncM , syncthing @@ -88,33 +79,11 @@ , DeviceError(..) , SyncError(..) - -- * Data Types- , CacheEntry(..)- , Config(..)- , AddressType(..)- , FolderConfig(..)- , DeviceConfig(..)- , VersioningConfig(..)- , GuiConfig(..)- , OptionsConfig(..)- , Connection(..)- , DirTree(..)- , Error(..)- , Ignore(..)- , Model(..)- , ModelState(..)- , Need(..)- , Progress(..)- , System(..)- , SystemMsg(..)- , Upgrade(..)- , Version(..)- -- * Utility functions- , parseAddr - , encodeAddr- , toUTC- , fromUTC+ , module Network.Syncthing.Utils++ -- * Types+ , module Network.Syncthing.Types ) where import Control.Applicative ((<$>))@@ -134,8 +103,8 @@ import Network.Syncthing.Internal.Error import qualified Network.Syncthing.Internal.Lens as PL import Network.Syncthing.Internal.Monad-import Network.Syncthing.Internal.Utils import Network.Syncthing.Types+import Network.Syncthing.Utils -- | Use Wreq's getWith and postWith functions when running in IO@@ -223,6 +192,10 @@ , _pHttps = False , _pManager = Left defaultManagerSettings }++-- | The default folder name.+defaultFolder :: FolderName+defaultFolder = "default" defaultResponseTimeout :: Int defaultResponseTimeout = 300000000
Network/Syncthing/Get.hs view
@@ -44,7 +44,7 @@ import Network.Syncthing.Internal.Error import Network.Syncthing.Internal.Monad import Network.Syncthing.Internal.Request-import Network.Syncthing.Types+import Network.Syncthing.Internal.Types -- | Ping the Syncthing server. Returns the string \"pong\".
Network/Syncthing/Internal.hs view
@@ -12,6 +12,10 @@ , module Network.Syncthing.Internal.Request -- * Error Handling , module Network.Syncthing.Internal.Error+ -- * Utils+ , module Network.Syncthing.Internal.Utils++ , module Network.Syncthing.Internal.Types ) where @@ -20,4 +24,6 @@ import Network.Syncthing.Internal.Monad hiding (liftEither, liftInner, liftReader) import Network.Syncthing.Internal.Request+import Network.Syncthing.Internal.Types+import Network.Syncthing.Internal.Utils
+ Network/Syncthing/Internal/Types.hs view
@@ -0,0 +1,26 @@++{-# OPTIONS_HADDOCK hide #-}++module Network.Syncthing.Internal.Types+ ( module Ty + ) where+++import Network.Syncthing.Types.CacheEntry as Ty+import Network.Syncthing.Types.Common as Ty+import Network.Syncthing.Types.Completion as Ty+import Network.Syncthing.Types.Config as Ty+import Network.Syncthing.Types.Connection as Ty+import Network.Syncthing.Types.DeviceId as Ty+import Network.Syncthing.Types.DirTree as Ty+import Network.Syncthing.Types.Error as Ty+import Network.Syncthing.Types.Ignore as Ty+import Network.Syncthing.Types.Model as Ty+import Network.Syncthing.Types.Need as Ty+import Network.Syncthing.Types.Ping as Ty+import Network.Syncthing.Types.Sync as Ty+import Network.Syncthing.Types.System as Ty+import Network.Syncthing.Types.SystemMsg as Ty+import Network.Syncthing.Types.Upgrade as Ty+import Network.Syncthing.Types.Version as Ty+
Network/Syncthing/Post.hs view
@@ -39,7 +39,7 @@ import Network.Syncthing.Internal.Monad import Network.Syncthing.Internal.Request-import Network.Syncthing.Types+import Network.Syncthing.Internal.Types maybeSystemMsg :: MonadSync m => SyncRequest -> SyncM m (Maybe SystemMsg)
Network/Syncthing/Types.hs view
@@ -1,24 +1,49 @@ ++-- |+-- Module : Network.Syncthing.Types+-- Copyright : (c) 2014 Jens Thomas+--+-- License : BSD-style+-- Maintainer : jetho@gmx.de+-- Stability : experimental+-- Portability : GHC+--+-- Type synonyms and data types.+ module Network.Syncthing.Types- ( module Ty+ ( + -- * Type Synonyms+ Server+ , Device+ , FolderName+ , Path+ , Host+ , Port+ , Addr+ + -- * Data Types+ , CacheEntry(..)+ , Config(..)+ , AddressType(..)+ , FolderConfig(..)+ , DeviceConfig(..)+ , VersioningConfig(..)+ , GuiConfig(..)+ , OptionsConfig(..)+ , Connection(..)+ , DirTree(..)+ , Error(..)+ , Ignore(..)+ , Model(..)+ , ModelState(..)+ , Need(..)+ , Progress(..)+ , System(..)+ , SystemMsg(..)+ , Upgrade(..)+ , Version(..) ) where --import Network.Syncthing.Types.CacheEntry as Ty-import Network.Syncthing.Types.Common as Ty-import Network.Syncthing.Types.Completion as Ty-import Network.Syncthing.Types.Config as Ty-import Network.Syncthing.Types.Connection as Ty-import Network.Syncthing.Types.DeviceId as Ty-import Network.Syncthing.Types.DirTree as Ty-import Network.Syncthing.Types.Error as Ty-import Network.Syncthing.Types.Ignore as Ty-import Network.Syncthing.Types.Model as Ty-import Network.Syncthing.Types.Need as Ty-import Network.Syncthing.Types.Ping as Ty-import Network.Syncthing.Types.Sync as Ty-import Network.Syncthing.Types.System as Ty-import Network.Syncthing.Types.SystemMsg as Ty-import Network.Syncthing.Types.Upgrade as Ty-import Network.Syncthing.Types.Version as Ty+import Network.Syncthing.Internal.Types
Network/Syncthing/Types/Common.hs view
@@ -10,7 +10,6 @@ , Host , Port , Addr- , defaultFolder ) where import Data.Text (Text)@@ -30,8 +29,4 @@ type Port = Int type Addr = (Host, Maybe Port)---- | The default folder name.-defaultFolder :: FolderName-defaultFolder = "default"
+ Network/Syncthing/Utils.hs view
@@ -0,0 +1,18 @@++-- |+-- Module : Network.Syncthing.Utils+-- Copyright : (c) 2014 Jens Thomas+--+-- License : BSD-style+-- Maintainer : jetho@gmx.de+-- Stability : experimental+-- Portability : GHC+--+-- Some useful utility functions.++module Network.Syncthing.Utils+ ( module Network.Syncthing.Internal.Utils+ ) where++import Network.Syncthing.Internal.Utils+
README.md view
@@ -2,6 +2,7 @@ syncthing-hs ============ +[](https://hackage.haskell.org/package/syncthing-hs) [](https://travis-ci.org/jetho/syncthing-hs) Haskell bindings for the [Syncthing REST API](https://github.com/syncthing/syncthing/wiki/REST-Interface).
+ changelog.md view
@@ -0,0 +1,10 @@+0.1.1.0+-------+* Add test-suite source files+* Add module Network.Syncthing.Types+* Add module Network.Syncthing.Utils++0.1.0.0+-------+* Initial release.+
syncthing-hs.cabal view
@@ -1,5 +1,5 @@ name: syncthing-hs-version: 0.1.0.0+version: 0.1.1.0 synopsis: Haskell bindings for the Syncthing REST API description: .@@ -16,7 +16,7 @@ -- copyright: category: Network build-type: Simple-extra-source-files: README.md+extra-source-files: README.md changelog.md cabal-version: >=1.10 library@@ -26,13 +26,15 @@ Network.Syncthing.Get Network.Syncthing.Post Network.Syncthing.Internal+ Network.Syncthing.Types+ Network.Syncthing.Utils other-modules: Network.Syncthing.Internal.Config Network.Syncthing.Internal.Error Network.Syncthing.Internal.Monad Network.Syncthing.Internal.Request Network.Syncthing.Internal.Lens+ Network.Syncthing.Internal.Types Network.Syncthing.Internal.Utils- Network.Syncthing.Types Network.Syncthing.Types.CacheEntry Network.Syncthing.Types.Common Network.Syncthing.Types.Completion@@ -76,25 +78,25 @@ build-depends: aeson >=0.8.0.1 , base >=4.5 && <5 , bytestring >=0.9- , connection >= 0.2.3 , containers >= 0.5.5.1+ , derive , either >=4.3.1- , http-client >=0.3.1.1- , http-client-tls >=0.2 , lens >=4.5 - , old-locale >= 1.0.0.6- , regex-posix >= 0.95.2- , text >=1.2.0.0- , time >= 1.4.2- , transformers >=0.3.0.0- , unordered-containers >= 0.2.5.1- , wreq >=0.3.0.0- build-depends: derive , quickcheck-instances+ , syncthing-hs , tasty , tasty-hunit , tasty-quickcheck- hs-source-dirs: tests, .+ , text >=1.2.0.0+ , transformers >=0.3.0.0+ , wreq >=0.3.0.0+ other-modules: Properties.ErrorProperties+ Properties.JsonArbitrary+ Properties.JsonInstances+ Properties.JsonProperties+ UnitTests.Errors+ UnitTests.Requests+ hs-source-dirs: tests default-language: Haskell2010 source-repository head
+ tests/Properties/ErrorProperties.hs view
@@ -0,0 +1,51 @@++{-# LANGUAGE OverloadedStrings #-}++module Properties.ErrorProperties+ ( errorProps+ ) where++import Control.Applicative ((<$>))+import Control.Monad (ap)+import qualified Data.ByteString.Lazy.Char8 as BS+import Data.Char (chr)+import qualified Data.Text as T+import Test.Tasty+import Test.Tasty.QuickCheck++import Network.Syncthing.Internal+++newtype FolderErrText = FolderErrText { getFolderErrText :: BS.ByteString }+ deriving (Eq, Show)++printableString :: Gen String+printableString = listOf1 . elements $ map chr [32 .. 126]++instance Arbitrary FolderErrText where+ arbitrary = FolderErrText . BS.pack . wrapText <$> printableString+ where wrapText t = "Folder " ++ t ++ " does not exist"++instance Arbitrary DeviceError where+ arbitrary = OtherDeviceError . T.pack <$> otherErrText+ where + otherErrText = printableString `suchThat` flip notElem reservedMsgs+ reservedMsgs = [ "device ID invalid: incorrect length"+ , "check digit incorrect"+ ]++encodeDeviceError :: DeviceError -> T.Text+encodeDeviceError (OtherDeviceError errMsg) = errMsg++prop_folderErr :: FolderErrText -> Bool+prop_folderErr = (Just NoSuchFolder ==) . decodeError . getFolderErrText++prop_deviceErr :: DeviceError -> Bool+prop_deviceErr = ap (==) (decodeDeviceError . encodeDeviceError)++errorProps :: TestTree+errorProps = testGroup "Decoding Errors"+ [ testProperty "NoSuchFolder"(prop_folderErr :: FolderErrText -> Bool)+ , testProperty "DeviceError" (prop_deviceErr :: DeviceError -> Bool)+ ]+
+ tests/Properties/JsonArbitrary.hs view
@@ -0,0 +1,149 @@++{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell #-}+++module Properties.JsonArbitrary where++import Control.Applicative (pure, (<$>), (<*>))+import Data.Char (isSpace)+import Data.Derive.Arbitrary+import Data.DeriveTH+import qualified Data.Map as M+import qualified Data.Text as T+import Test.QuickCheck.Instances+import Test.Tasty.QuickCheck++import Network.Syncthing.Internal+++newtype NonEmptyText = NonEmptyText {getNonEmptyText :: T.Text}+ deriving (Eq, Ord, Show, Read)++instance Arbitrary NonEmptyText where+ arbitrary = NonEmptyText . T.pack <$> listOf1 notSpace+ where notSpace = arbitrary `suchThat` (not . isSpace)+ shrink = map NonEmptyText+ . filter (not . T.all isSpace)+ . shrink+ . getNonEmptyText++genAddr :: Gen Addr+genAddr = (,) <$> host <*> port+ where+ host = T.pack <$> listOf1 hostChars+ hostChars = elements $ concat [['a'..'z'], ['A'.. 'Z'], ['0'..'9'], "."]+ port = fmap getNonNegative <$> arbitrary++instance Arbitrary CacheEntry where+ arbitrary = CacheEntry <$> genAddr <*> arbitrary++instance Arbitrary Connection where+ arbitrary = Connection <$> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> genAddr+ <*> arbitrary++instance Arbitrary SystemMsg where+ arbitrary = oneof $ otherSystemMsg : knownMessages+ where+ knownMessages = map pure [Restarting, ShuttingDown, ResettingFolders]+ otherSystemMsg = OtherSystemMsg <$> notReservedMsg+ notReservedMsg = arbitrary `suchThat` flip notElem reservedMsgs+ reservedMsgs = ["restarting", "shutting down", "resetting folders"]++instance Arbitrary Model where+ arbitrary =+ Model <$> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> (fmap getNonEmptyText <$> arbitrary)+ <*> arbitrary++instance Arbitrary GuiConfig where+ arbitrary =+ GuiConfig <$> arbitrary+ <*> (fmap getNonEmptyText <$> arbitrary)+ <*> genAddr+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary++instance Arbitrary DeviceConfig where+ arbitrary =+ DeviceConfig <$> arbitrary+ <*> arbitrary+ <*> (listOf $ oneof [pure Dynamic, Address <$> genAddr])+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary++instance Arbitrary OptionsConfig where+ arbitrary =+ OptionsConfig <$> (listOf genAddr)+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary++instance Arbitrary DirTree where+ arbitrary = choose (0, 5) >>= dirTree+ where+ genFile = File <$> arbitrary <*> arbitrary++ dirTree :: Int -> Gen DirTree+ dirTree 0 = genFile+ dirTree n | n>0 = frequency [(2, genFile), (1, Dir <$> dirContents)]+ where+ dirContents = M.fromList <$> listOf dirEntry+ dirEntry = (,) <$> entryName <*> dirTree (n `div` 2)+ entryName = getNonEmptyText <$> arbitrary+++-- | Let Template Haskell derive trivial instances.+concat <$> mapM (derive makeArbitrary)+ [ ''AddressType+ , ''FolderConfig+ , ''VersioningConfig+ , ''Config+ , ''Version+ , ''Ping+ , ''Completion+ , ''ModelState+ , ''Upgrade+ , ''Ignore+ , ''Progress+ , ''Need+ , ''Sync+ , ''DeviceError+ , ''Error+ , ''Errors+ , ''System+ ]+
+ tests/Properties/JsonInstances.hs view
@@ -0,0 +1,158 @@++{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE FlexibleInstances #-}+++module Properties.JsonInstances where++import Control.Applicative ((<$>), pure)+import Data.Aeson hiding (Error)+import Data.Maybe (fromMaybe)+import qualified Data.Text as T++import Network.Syncthing.Internal+++singleField :: ToJSON a => T.Text -> a -> Value+singleField fieldName = object . pure . (fieldName .=)++encodeMaybe = fromMaybe ""++encodeUTC = encodeMaybe . fmap fromUTC ++encodeInvalid = encodeMaybe . fmap T.unpack ++encodeModelState = encodeMaybe . fmap encodeState+ where encodeState state = + case state of+ Idle -> "idle"+ Scanning -> "scanning"+ Cleaning -> "cleaning"+ Syncing -> "syncing"++instance ToJSON Version where+ toJSON Version{..} =+ object [ "arch" .= getArch+ , "longVersion" .= getLongVersion+ , "os" .= getOs+ , "version" .= getVersion+ ]++instance ToJSON Ping where+ toJSON = singleField "ping" . getPing++instance ToJSON Completion where+ toJSON = singleField "completion" . getCompletion ++instance ToJSON Sync where+ toJSON = singleField "configInSync" . getSync ++instance ToJSON CacheEntry where+ toJSON CacheEntry{..} =+ object [ "Address" .= encodeAddr getAddr+ , "Seen" .= encodeUTC getSeen+ ]++instance ToJSON Connection where+ toJSON Connection{..} =+ object [ "At" .= encodeUTC getAt+ , "InBytesTotal" .= getInBytesTotal+ , "OutBytesTotal" .= getOutBytesTotal+ , "Address" .= encodeAddr getAddress+ , "ClientVersion" .= getClientVersion+ ]++instance ToJSON Model where+ toJSON Model{..} =+ object [ "globalBytes" .= getGlobalBytes + , "globalDeleted" .= getGlobalDeleted + , "globalFiles" .= getGlobalFiles + , "inSyncBytes" .= getInSyncBytes + , "inSyncFiles" .= getInSyncFiles + , "localBytes" .= getLocalBytes + , "localDeleted" .= getLocalDeleted + , "localFiles" .= getLocalFiles + , "needBytes" .= getNeedBytes + , "needFiles" .= getNeedFiles + , "state" .= encodeModelState getState + , "stateChanged" .= encodeUTC getStateChanged + , "invalid" .= encodeInvalid getInvalid+ , "version" .= getModelVersion + ]++instance ToJSON Upgrade where+ toJSON Upgrade{..} =+ object [ "latest" .= getLatest+ , "newer" .= getNewer+ , "running" .= getRunning+ ]++instance ToJSON Ignore where+ toJSON Ignore{..} =+ object [ "ignore" .= getIgnores+ , "patterns" .= getPatterns+ ]++instance ToJSON Need where+ toJSON Need{..} =+ object [ "progress" .= getProgress+ , "queued" .= getQueued+ , "rest" .= getRest+ ]++instance ToJSON Progress where+ toJSON Progress{..} =+ object [ "Name" .= getName + , "Flags" .= getFlags + , "Modified" .= getModified + , "Version" .= getProgressVersion + , "LocalVersion" .= getLocalVersion + , "NumBlocks" .= getNumBlocks + , "Size" .= getSize + ]++instance ToJSON System where+ toJSON System{..} =+ object [ "alloc" .= getAlloc + , "cpuPercent" .= getCpuPercent + , "extAnnounceOK" .= getExtAnnounceOK + , "goroutines" .= getGoRoutines + , "myID" .= getMyId + , "sys" .= getSys + ]++instance ToJSON (Either DeviceError Device) where+ toJSON = object . pure . either deviceError deviceId + where deviceError = ("error" .=) . encodeDeviceError + deviceId = ("id" .=) ++encodeDeviceError :: DeviceError -> T.Text+encodeDeviceError err = + case err of+ IncorrectLength -> "device ID invalid: incorrect length"+ IncorrectCheckDigit -> "check digit incorrect"+ OtherDeviceError e -> e++instance ToJSON SystemMsg where+ toJSON msg = object [ "ok" .= decodedSystemMsg ]+ where + decodedSystemMsg = case msg of+ Restarting -> "restarting"+ ShuttingDown -> "shutting down"+ ResettingFolders -> "resetting folders"+ OtherSystemMsg m -> m++instance ToJSON Error where+ toJSON Error{..} =+ object [ "Time" .= encodeUTC getTime+ , "Error" .= getMsg+ ]++instance ToJSON Errors where+ toJSON = singleField "errors" . getErrors ++instance ToJSON DirTree where+ toJSON Dir{..} = toJSON getDirContents+ toJSON File{..} = toJSON [getModTime, getFileSize] +
+ tests/Properties/JsonProperties.hs view
@@ -0,0 +1,52 @@++module Properties.JsonProperties+ ( jsonProps+ ) where++import Data.Aeson +import Test.Tasty+import Test.Tasty.QuickCheck++import Network.Syncthing.Internal++import Properties.JsonArbitrary+import Properties.JsonInstances+++type EitherDeviceErrorId = Either DeviceError Device+++genProp name prop = testProperty testName prop+ where+ testName = name ++ " == decode . encode"++prop_json :: (Eq a, FromJSON a, ToJSON a) => a -> Bool+prop_json x = Just x == (decode . encode $ x)++jsonProps :: TestTree+jsonProps = testGroup "JSON Parsers"+ [ genProp "Ping" (prop_json :: Ping -> Bool)+ , genProp "Version" (prop_json :: Version -> Bool)+ , genProp "Completion" (prop_json :: Completion -> Bool)+ , genProp "CacheEntry" (prop_json :: CacheEntry -> Bool)+ , genProp "Connection" (prop_json :: Connection -> Bool)+ , genProp "Model" (prop_json :: Model -> Bool)+ , genProp "Upgrade" (prop_json :: Upgrade -> Bool)+ , genProp "Ignore" (prop_json :: Ignore -> Bool)+ , genProp "Progress" (prop_json :: Progress -> Bool)+ , genProp "Need" (prop_json :: Need -> Bool)+ , genProp "Sync" (prop_json :: Sync -> Bool)+ , genProp "DeviceId" (prop_json :: EitherDeviceErrorId -> Bool)+ , genProp "SystemMsg" (prop_json :: SystemMsg -> Bool)+ , genProp "VersioningConfig" (prop_json :: VersioningConfig -> Bool)+ , genProp "FolderConfig" (prop_json :: FolderConfig -> Bool)+ , genProp "GuiConfig" (prop_json :: GuiConfig -> Bool)+ , genProp "OptionsConfig" (prop_json :: OptionsConfig -> Bool)+ , genProp "DeviceConfig" (prop_json :: DeviceConfig -> Bool)+ , genProp "Config" (prop_json :: Config -> Bool)+ , genProp "Error" (prop_json :: Error -> Bool)+ , genProp "Errors" (prop_json :: Errors -> Bool)+ , genProp "System" (prop_json :: System -> Bool)+ , genProp "DirTree" (prop_json :: DirTree -> Bool)+ ]+
+ tests/UnitTests/Errors.hs view
@@ -0,0 +1,53 @@++{-# LANGUAGE OverloadedStrings #-}++module UnitTests.Errors+ ( errorUnits+ ) where++import qualified Data.ByteString.Lazy.Char8 as BS+import qualified Data.Text as T+import Test.Tasty+import Test.Tasty.HUnit++import Network.Syncthing.Internal+++createTestName :: Show err => err -> String+createTestName = ("Decode " ++) . show++createDescription :: Show err => err -> String -> String+createDescription errType errMsg =+ concat [show errMsg, " decodes to ", show errType]++testDecodeError :: SyncError -> BS.ByteString -> TestTree+testDecodeError errType errMsg =+ testCase (createTestName errType) $+ assertEqual (createDescription errType $ BS.unpack errMsg)+ (Just errType)+ (decodeError errMsg)++testDecodeDeviceError :: DeviceError -> T.Text -> TestTree+testDecodeDeviceError errType errMsg =+ testCase (createTestName errType) $+ assertEqual (createDescription errType $ T.unpack errMsg)+ errType+ (decodeDeviceError errMsg)+++errorUnits :: TestTree+errorUnits = testGroup "Unit Tests for error messages" $+ map (uncurry testDecodeError)+ [ (CSRFError, "CSRF Error")+ , (NotAuthorized, "Not Authorized")+ , (NotFound, "404 page not found")+ , (NoSuchFolder, "no such folder")+ , ((InvalidDeviceId IncorrectLength), "device ID invalid: incorrect length")+ , ((InvalidDeviceId IncorrectCheckDigit), "check digit incorrect")+ ]+ +++ map (uncurry testDecodeDeviceError)+ [ (IncorrectLength, "device ID invalid: incorrect length")+ , (IncorrectCheckDigit, "check digit incorrect")+ ]+
+ tests/UnitTests/Requests.hs view
@@ -0,0 +1,285 @@++{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}++module UnitTests.Requests+ ( requestUnits+ ) where++import Control.Applicative ((<$>))+import Control.Lens ((&), (.~), (?~), (^.))+import Control.Monad.Trans.Either (runEitherT)+import Control.Monad.Trans.Reader (runReaderT)+import Control.Monad.Trans.Writer (Writer, execWriter, tell)+import Data.Aeson (ToJSON, Value, toJSON)+import Data.List (isPrefixOf, sort)+import qualified Data.Map as M+import qualified Data.Text as T+import Data.Text.Encoding (encodeUtf8)+import qualified Network.Wreq as W+import Test.Tasty+import Test.Tasty.HUnit+import Test.Tasty.QuickCheck++import Network.Syncthing+import qualified Network.Syncthing.Get as Get+import Network.Syncthing.Internal+import qualified Network.Syncthing.Post as Post++import Properties.JsonArbitrary+import Properties.JsonInstances++++-------------- Test Infrastructure --------------++type Endpoint = String+type Url = String+type Params = [Param]++data RequestType = GET | POST+ deriving (Eq, Show)++data LoggedRequest = LoggedRequest {+ reqType :: RequestType+ , reqUrl :: String+ , reqOptions :: W.Options+ , reqPayload :: Maybe Value+ }++type RequestLogger = Writer [LoggedRequest]+type LogAction = SyncM RequestLogger+type LogResult a = RequestLogger (SyncResult a)++instance MonadSync RequestLogger where+ getMethod o s = tell [ LoggedRequest GET s o Nothing ] >> return ""+ postMethod o s p = tell [ LoggedRequest POST s o (Just p) ] >> return ""++mockedSyncthing :: SyncConfig -> LogAction a -> LogResult a+mockedSyncthing config action =+ flip runReaderT config $ runEitherT $ runSyncthing action++extractRequest :: LogResult a -> LoggedRequest+extractRequest = head . execWriter++execRequest :: SyncConfig -> LogAction a -> LoggedRequest+execRequest cfg action = extractRequest $ mockedSyncthing cfg action++withConfigRequest :: SyncConfig -> LogAction a -> (LoggedRequest -> b) -> b+withConfigRequest cfg action f = f $ execRequest cfg action++withRequest :: LogAction a -> (LoggedRequest -> b) -> b+withRequest = withConfigRequest defaultConfig++++-------------- Helper Functions --------------++noPayload :: ()+noPayload = ()++noParams :: Params+noParams = []++createIgnoresMap :: [T.Text] -> M.Map T.Text [T.Text] +createIgnoresMap = M.singleton "ignore" ++serverString :: SyncConfig -> String+serverString = T.unpack . (^. pServer)++assertReqType :: RequestType -> RequestType -> Assertion+assertReqType rType reqType =+ assertEqual (show rType ++ " Request is executed") rType reqType ++assertUrl :: SyncConfig -> Endpoint -> Url -> Assertion+assertUrl cfg endpoint reqUrl =+ let url = "http://" ++ serverString cfg ++ endpoint+ in assertEqual "Request url is correct" url reqUrl++assertParams :: Params -> W.Options -> Assertion+assertParams params reqOptions =+ let reqParams = reqOptions ^. W.params+ in assertEqual "Params set correctly" (sort params) (sort reqParams)++assertPayload :: ToJSON p => p -> Maybe Value -> Assertion +assertPayload payload reqPayload =+ let payload' = Just . toJSON $ payload+ in assertEqual "Payload injected correctly" payload' reqPayload++assertGet :: LoggedRequest -> Endpoint -> Params -> Assertion+assertGet LoggedRequest{..} endpoint params = do+ assertReqType GET reqType+ assertUrl defaultConfig endpoint reqUrl+ assertParams params reqOptions++assertPost :: ToJSON p => LoggedRequest -> Endpoint -> Params -> p -> Assertion+assertPost LoggedRequest{..} endpoint params payload = do+ assertReqType POST reqType+ assertUrl defaultConfig endpoint reqUrl+ assertParams params reqOptions+ assertPayload payload reqPayload++++-------------- Basic Tests --------------++basicRequest rType endpoint action = withRequest action $+ \LoggedRequest{..} -> do+ assertReqType rType reqType + assertUrl defaultConfig endpoint reqUrl+ assertEqual "Accept header contains 'application/json'"+ ["application/json"] (reqOptions ^. W.header "Accept")++changeServer =+ let server = "192.168.0.10:8080"+ cfg = defaultConfig & pServer .~ server+ in+ withConfigRequest cfg Get.ping $+ \LoggedRequest{..} -> assertUrl cfg "/rest/ping" reqUrl++setApiKey =+ let apiKey = "123456789XYZ"+ cfg = defaultConfig & pApiKey ?~ apiKey+ in+ withConfigRequest cfg Get.ping $+ \LoggedRequest{..} -> + assertEqual "ApiKey is set as X-API-KEY header"+ [encodeUtf8 apiKey] (reqOptions ^. W.header "X-API-KEY")++enableAuth =+ let auth = W.basicAuth "user" "pass"+ cfg = defaultConfig & pAuth ?~ auth+ in+ withConfigRequest cfg Get.ping $+ \LoggedRequest{..} -> + assertEqual "Auth enabled" (Just auth) (reqOptions ^. W.auth)++enableHttps =+ let cfg = defaultConfig & pHttps .~ True+ in+ withConfigRequest cfg Get.ping $+ \LoggedRequest{..} -> + assertBool "HTTPS protocol is used" $ "https://" `isPrefixOf` reqUrl++disableHttps =+ let cfg = defaultConfig & pHttps .~ False+ in+ withConfigRequest cfg Get.ping $+ \LoggedRequest{..} -> + assertBool "HTTP protocol is used" $ "http://" `isPrefixOf` reqUrl++++-------------- GET and POST Requests --------------++testGet :: Endpoint -> Params -> LogAction a -> TestTree+testGet endpoint params action = withRequest action $+ \loggedRequest ->+ testCase ("Test GET " ++ endpoint) $ + assertGet loggedRequest endpoint params ++testPost :: ToJSON p => Endpoint -> Params -> p -> LogAction a -> TestTree+testPost endpoint params payload action = withRequest action $+ \loggedRequest ->+ testCase ("Test POST " ++ endpoint) $ + assertPost loggedRequest endpoint params payload++-- | Post.sendConfig requires special treatment. Use Quickcheck to generate+-- sample data for the payload.+testPostConfig :: Endpoint -> Params -> TestTree+testPostConfig endpoint params = + testCase ("Test POST " ++ endpoint) $ do+ configSample <- head <$> sample' (arbitrary :: Gen Config)+ withRequest (Post.sendConfig configSample) $ + \loggedRequest -> + assertPost loggedRequest endpoint params configSample++++-------------- Test Suite --------------++requestUnits :: TestTree+requestUnits = testGroup "Unit Tests for Requests" + [ testGroup "Basic Tests"+ [ testCase "GET Request" $ basicRequest GET "/rest/ping" Get.ping+ , testCase "POST Request" $ basicRequest POST "/rest/ping" Post.ping+ , testCase "changeServer" changeServer+ , testCase "set ApiKey" setApiKey+ , testCase "enable Authentication" enableAuth+ , testCase "enable HTTPS usage" enableHttps+ , testCase "disable HTTPS usage" disableHttps+ ]+ , testGroup "GET Requests"+ [ testGet "/rest/ping" noParams Get.ping+ , testGet "/rest/completion"+ [("folder","default"), ("device", "device1")] + (Get.completion "device1" "default")+ , testGet "/rest/config" noParams Get.config+ , testGet "/rest/connections" noParams Get.connections+ , testGet "/rest/deviceid" + [("id", "device1")] + (Get.deviceId "device1")+ , testGet "/rest/discovery" noParams Get.discovery+ , testGet "/rest/errors" noParams Get.errors+ , testGet "/rest/ignores" + [("folder", "default")] + (Get.ignores "default")+ , testGet "/rest/model" + [("folder", "default")] + (Get.model "default")+ , testGet "/rest/need" + [("folder", "default")] + (Get.need "default")+ , testGet "/rest/config/sync" noParams Get.sync+ , testGet "/rest/system" noParams Get.system+ , testGet "/rest/tree" + [("folder", "default")]+ (Get.tree "default" Nothing Nothing)+ , testGet "/rest/tree" + [("folder", "default"), ("prefix", "foo/bar")]+ (Get.tree "default" (Just "foo/bar") Nothing)+ , testGet "/rest/tree" + [("folder", "default"), ("levels", "2")]+ (Get.tree "default" Nothing (Just 2))+ , testGet "/rest/tree" + [("folder", "default"),("prefix", "foo/bar"),("levels", "2")]+ (Get.tree "default" (Just "foo/bar") (Just 2))+ , testGet "/rest/upgrade" noParams Get.upgrade+ , testGet "/rest/version" noParams Get.version+ ]+ , testGroup "POST Requests"+ [ testPost "/rest/ping" noParams noPayload Post.ping+ , testPost "/rest/bump"+ [("folder", "default"), ("file", "foo/bar")] + noPayload+ (Post.bump "default" "foo/bar")+ , testPost "/rest/discovery/hint"+ [("device", "device1"), ("addr", "192.168.0.10:8080")] + noPayload+ (Post.hint "device1" "192.168.0.10:8080")+ , testPost "/rest/error" + noParams + (T.pack "Error 1") + (Post.sendError "Error 1")+ , testPost "/rest/error/clear" noParams noPayload Post.clearErrors+ , testPost "/rest/scan" + [("folder", "default")] + noPayload + (Post.scanFolder "default" Nothing)+ , testPost "/rest/scan"+ [("folder", "default"), ("sub", "foo/bar")] + noPayload + (Post.scanFolder "default" (Just "foo/bar"))+ , testPost "/rest/restart" noParams noPayload Post.restart+ , testPost "/rest/shutdown" noParams noPayload Post.shutdown+ , testPost "/rest/reset" noParams noPayload Post.reset+ , testPost "/rest/upgrade" noParams noPayload Post.upgrade+ , testPost "/rest/ignores" + [("folder", "default")] + (createIgnoresMap ["file1", "file2", "foo/bar"])+ (Post.sendIgnores "default" ["file1", "file2", "foo/bar"])+ , testPostConfig "/rest/config" noParams+ ]+ ]+