From c0f3f924ff183d900d63c0b4ae9f22a6ee6b725e Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Mon, 8 May 2023 09:57:16 -0400 Subject: [PATCH] remove some repetition in announcement definitions --- test/Spec.hs | 65 ++++++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 48 deletions(-) diff --git a/test/Spec.hs b/test/Spec.hs index cf7bcce..0119261 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -72,6 +72,16 @@ data BespokeFailure = BespokeFailure deriving (Show) instance Exception BespokeFailure +-- | Make an announcement that's real enough to convince a test. +simpleAnnouncement :: T.Text -> T.Text -> (T.Text, StorageServerAnnouncement) +simpleAnnouncement nick furl = + ( T.concat ["v0-", nick] + , def + { storageServerAnnouncementFURL = Just furl + , storageServerAnnouncementNick = Just nick + } + ) + tests :: TestTree tests = testGroup @@ -113,10 +123,7 @@ tests = let ann = def{storageServerAnnouncementNick = Just "unreachable"} anns = Map.fromList - [ - ( "v0-abc123" - , ann - ) + [ ("v0-abc123", ann) ] result <- liftIO $ download anns (trivialCap 1 1) noServers @@ -128,16 +135,7 @@ tests = -- If we can't recover enough shares from the configured servers -- then we can't possibly get enough shares to recover the -- application data. - let anns = - Map.fromList - [ - ( "v0-abc123" - , def - { storageServerAnnouncementFURL = Just "somewhere" - , storageServerAnnouncementNick = Just "abc123" - } - ) - ] + let anns = Map.fromList [simpleAnnouncement "abc123" "somewhere"] cap = trivialCap 3 3 -- Two shares exist. @@ -163,20 +161,8 @@ tests = -- recover the application data. Duplicate shares do us no good. let anns = Map.fromList - [ - ( "v0-abc123" - , def - { storageServerAnnouncementFURL = Just "somewhere" - , storageServerAnnouncementNick = Just "abc123" - } - ) - , - ( "v0-abc456" - , def - { storageServerAnnouncementFURL = Just "elsewhere" - , storageServerAnnouncementNick = Just "abc123" - } - ) + [ simpleAnnouncement "abc123" "somewhere" + , simpleAnnouncement "abc456" "elsewhere" ] cap = trivialCap 3 3 @@ -206,16 +192,7 @@ tests = result , testCase "IO exceptions from storageServerGetBuckets are handled" $ do -- An announcement for our server - let anns = - Map.fromList - [ - ( "v0-abc123" - , def - { storageServerAnnouncementFURL = Just "somewhere" - , storageServerAnnouncementNick = Just "abc123" - } - ) - ] + let anns = Map.fromList [simpleAnnouncement "abc123" "somewhere"] -- A broken interface to the server server <- breakGetBuckets BespokeFailure <$> memoryStorageServer @@ -236,16 +213,8 @@ tests = result , testCase "IO exceptions from storageServerRead are handled" $ do -- An announcement for our server - let anns = - Map.fromList - [ - ( "v0-abc123" - , def - { storageServerAnnouncementFURL = Just "somewhere" - , storageServerAnnouncementNick = Just "abc123" - } - ) - ] + let anns = Map.fromList [simpleAnnouncement "abc123" "somewhere"] + -- A broken interface to the server server <- breakRead BespokeFailure <$> memoryStorageServer -- GitLab