Skip to content
Snippets Groups Projects
Commit 42432738 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

handle one trivial failure case

parent c86e8833
No related branches found
No related tags found
1 merge request!1Simplistic implementation of download
......@@ -65,7 +65,7 @@ library
import: warnings
-- Modules exported by the library.
exposed-modules:
exposed-modules: Tahoe.Download
-- Modules included in this library but not exported.
-- other-modules:
......@@ -76,8 +76,11 @@ library
-- Other library packages from which modules are imported.
build-depends:
, base ^>=4.14.3.0
, bytestring
, containers
, tahoe-chk
, tahoe-great-black-swamp
, text
-- Directories containing source files.
hs-source-dirs: src
......@@ -111,27 +114,35 @@ executable gbs-downloader
test-suite gbs-downloader-test
-- Import common warning flags.
import: warnings
import: warnings
-- Base language which the package is written in.
default-language: Haskell2010
default-language: Haskell2010
-- Modules included in this executable, other than Main.
-- other-modules:
-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
default-extensions:
OverloadedStrings
RecordWildCards
-- The interface type and version of the test suite.
type: exitcode-stdio-1.0
type: exitcode-stdio-1.0
-- Directories containing source files.
hs-source-dirs: test
hs-source-dirs: test
-- The entrypoint to the test suite.
main-is: Main.hs
main-is: Spec.hs
-- Test dependencies.
build-depends:
, base ^>=4.14.3.0
, bytestring
, crypto-api
, gbs-downloader
, hedgehog
, tahoe-chk
, tasty
, tasty-hunit
module Tahoe.Download (DownloadError (..), download) where
import Data.ByteString.Lazy (ByteString)
import Data.Map.Strict (Map)
import Tahoe.CHK.Capability (Reader)
import Tahoe.CHK.Server (StorageServerAnnouncement, StorageServerID)
{- | An unrecoverable problem arose while attempting to download and/or read
some application data.
-}
data DownloadError
= -- | The configuration included no candidate servers from which to download.
NoConfiguredServers
deriving (Eq, Ord, Show)
download ::
Map StorageServerID StorageServerAnnouncement ->
Reader ->
IO (Either DownloadError ByteString)
download servers cap
| mempty == servers = pure . Left $ NoConfiguredServers
module Main (main) where
main :: IO ()
main = putStrLn "Test suite not yet implemented."
module Main where
import Control.Monad.IO.Class (liftIO)
import Crypto.Classes (buildKey)
import qualified Data.ByteString as B
import System.IO (hSetEncoding, stderr, stdout, utf8)
import Tahoe.CHK.Capability (Reader (..), Verifier (..))
import Tahoe.Download (DownloadError (..))
import Test.Tasty (TestTree, defaultMain, testGroup)
import Test.Tasty.HUnit (assertEqual, testCase)
import Tahoe.Download (download)
tests :: TestTree
tests =
testGroup
"All tests"
[ testCase "no configured servers" $ do
-- If there are no servers then we can't possibly get enough
-- shares to recover the application data.
let Just readKey = buildKey $ B.replicate 32 0x00
storageIndex = B.replicate 32 0x00
fingerprint = B.replicate 32 0x00
required = 1
total = 1
size = 1234
verifier = Verifier{..}
cap = Reader{..}
result <- liftIO $ download mempty cap
assertEqual
"download should fail with no servers"
(Left NoConfiguredServers)
result
]
main :: IO ()
main = do
-- Hedgehog writes some non-ASCII and the whole test process will die if
-- it can't be encoded. Increase the chances that all of the output can
-- be encoded by forcing the use of UTF-8 (overriding the LANG-based
-- choice normally made).
hSetEncoding stdout utf8
hSetEncoding stderr utf8
defaultMain tests
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment