From 88bf7b229fb860bca896cf6d69ce1a989eee4ee1 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Mon, 8 May 2023 10:05:05 -0400 Subject: [PATCH] remove some more repetitions --- test/Spec.hs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/test/Spec.hs b/test/Spec.hs index 0119261..11671d6 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -82,6 +82,16 @@ simpleAnnouncement nick furl = } ) +{- | Build a lookup function that can look up any server in the given list + from its announcement. +-} +simpleLookup :: Applicative f => [(T.Text, b)] -> StorageServerAnnouncement -> f (Either LookupError b) +simpleLookup [] _ = pure . Left $ AnnouncementStructureUnmatched +simpleLookup ((furl, server) : ss) ann@StorageServerAnnouncement{storageServerAnnouncementFURL} = + if Just furl == storageServerAnnouncementFURL + then pure . pure $ server + else simpleLookup ss ann + tests :: TestTree tests = testGroup @@ -144,10 +154,7 @@ tests = storageServerWrite server (storageIndex . verifier $ cap) 1 0 "Hello world" -- Make the server reachable. - let openServer StorageServerAnnouncement{storageServerAnnouncementFURL} = - if storageServerAnnouncementFURL == Just "somewhere" - then pure . pure $ server - else pure . Left $ AnnouncementStructureUnmatched + let openServer = simpleLookup [("somewhere", server)] -- Try to download the cap which requires three shares to reconstruct. result <- liftIO $ download anns cap openServer @@ -178,11 +185,7 @@ tests = storageServerWrite elsewhere idx 0 offset "Hello world" -- Make the server reachable. - let openServer StorageServerAnnouncement{storageServerAnnouncementFURL} = - case storageServerAnnouncementFURL of - Just "somewhere" -> pure . pure $ somewhere - Just "elsewhere" -> pure . pure $ elsewhere - _ -> pure . Left $ AnnouncementStructureUnmatched + let openServer = simpleLookup [("somewhere", somewhere), ("elsewhere", elsewhere)] -- Try to download the cap which requires three shares to reconstruct. result <- liftIO $ download anns cap openServer @@ -197,10 +200,7 @@ tests = server <- breakGetBuckets BespokeFailure <$> memoryStorageServer -- Make the server reachable. - let openServer StorageServerAnnouncement{storageServerAnnouncementFURL} = - if storageServerAnnouncementFURL == Just "somewhere" - then pure . pure $ server - else pure . Left $ AnnouncementStructureUnmatched + let openServer = simpleLookup [("somewhere", server)] -- Something to pretend to try to download let cap = trivialCap 3 13 @@ -229,10 +229,7 @@ tests = storageServerWrite server idx 2 offset "Hello world" -- Make the server reachable. - let openServer StorageServerAnnouncement{storageServerAnnouncementFURL} = - if storageServerAnnouncementFURL == Just "somewhere" - then pure . pure $ server - else pure . Left $ AnnouncementStructureUnmatched + let openServer = simpleLookup [("somewhere", server)] -- Try to download the cap which requires three shares to reconstruct. -- GitLab