diff --git a/tests/Bots/BroadcastTests.hs b/tests/Bots/BroadcastTests.hs index 955e7bebb7..1def872096 100644 --- a/tests/Bots/BroadcastTests.hs +++ b/tests/Bots/BroadcastTests.hs @@ -14,7 +14,7 @@ import Control.Concurrent (forkIO, killThread, threadDelay) import Control.Exception (bracket) import Simplex.Chat.Bot.KnownContacts import Simplex.Chat.Core -import Simplex.Chat.Options (CoreChatOpts (..)) +import Simplex.Chat.Options (ChatOpts (..), CoreChatOpts (..)) import Simplex.Chat.Options.DB import Simplex.Chat.Types (ChatPeerType (..), Profile (..)) import Test.Hspec hiding (it) @@ -26,11 +26,11 @@ broadcastBotTests :: SpecWith TestParams broadcastBotTests = do it "should broadcast message" testBroadcastMessages -withBroadcastBot :: BroadcastBotOpts -> IO () -> IO () -withBroadcastBot opts test = +withBroadcastBot :: TestParams -> BroadcastBotOpts -> IO () -> IO () +withBroadcastBot ps opts test = bracket (forkIO bot) killThread (\_ -> threadDelay 500000 >> test) where - bot = simplexChatCore testCfg (mkChatOpts opts) $ broadcastBot opts + bot = simplexChatCore (fst $ testPortsCfg ps testCfg testOpts) (mkChatOpts opts) $ broadcastBot opts broadcastBotProfile :: Profile broadcastBotProfile = Profile {displayName = "broadcast_bot", fullName = "Broadcast Bot", shortDescr = Nothing, description = Nothing, image = Nothing, contactLink = Nothing, peerType = Just CPTBot, preferences = Nothing, badge = Nothing, contactDomain = Nothing} @@ -39,7 +39,7 @@ mkBotOpts :: TestParams -> [KnownContact] -> BroadcastBotOpts mkBotOpts ps publishers = BroadcastBotOpts { coreOptions = - testCoreOpts + coreOpts { dbOptions = (dbOptions testCoreOpts) #if defined(dbPostgres) @@ -54,6 +54,8 @@ mkBotOpts ps publishers = welcomeMessage = defaultWelcomeMessage publishers, prohibitedMessage = defaultWelcomeMessage publishers } + where + (_, ChatOpts {coreOptions = coreOpts}) = testPortsCfg ps testCfg testOpts botDbPrefix :: FilePath botDbPrefix = "broadcast_bot" @@ -67,7 +69,7 @@ testBroadcastMessages ps = do bc_bot ##> "/ad" getContactLink bc_bot True let botOpts = mkBotOpts ps [KnownContact 2 "alice"] - withBroadcastBot botOpts $ + withBroadcastBot ps botOpts $ withTestChat ps "alice" $ \alice -> withNewTestChat ps "bob" bobProfile $ \bob -> withNewTestChat ps "cath" cathProfile $ \cath -> do diff --git a/tests/Bots/DirectoryTests.hs b/tests/Bots/DirectoryTests.hs index 65a9e153ba..0607c76054 100644 --- a/tests/Bots/DirectoryTests.hs +++ b/tests/Bots/DirectoryTests.hs @@ -23,7 +23,7 @@ import System.Directory (emptyPermissions, setOwnerExecutable, setOwnerReadable, import Simplex.Chat.Bot.KnownContacts import Simplex.Chat.Controller (ChatConfig (..)) import qualified Simplex.Chat.Markdown as MD -import Simplex.Chat.Options (CoreChatOpts (..)) +import Simplex.Chat.Options (ChatOpts (..), CoreChatOpts (..)) import Simplex.Chat.Options.DB import Simplex.Chat.Protocol (memberSupportVoiceVersion) import Simplex.Chat.Types (ChatPeerType (..), Profile (..)) @@ -116,7 +116,7 @@ mkDirectoryOpts :: TestParams -> [KnownContact] -> Maybe KnownGroup -> Maybe Fil mkDirectoryOpts ps superUsers ownersGroup webFolder = DirectoryOpts { coreOptions = - testCoreOpts + coreOpts { dbOptions = (dbOptions testCoreOpts) #if defined(dbPostgres) @@ -149,6 +149,8 @@ mkDirectoryOpts ps superUsers ownersGroup webFolder = knocking = False, testing = True } + where + (_, ChatOpts {coreOptions = coreOpts}) = testPortsCfg ps testCfg testOpts serviceDbPrefix :: FilePath serviceDbPrefix = "directory_service" @@ -1650,7 +1652,7 @@ withDirectoryServiceOpts ps modOpts test = do ds ##> "/ad" getContactLink ds True let opts = modOpts $ mkDirectoryOpts ps [KnownContact 2 "alice"] Nothing Nothing - runDirectory testCfg opts $ + runDirectory ps testCfg opts $ withTestChatCfg ps testCfg "super_user" $ \superUser -> do superUser <## "subscribed 1 connections on server localhost" test superUser dsLink @@ -1808,16 +1810,16 @@ withDirectory ps cfg dsLink = withDirectoryOwnersGroup ps cfg dsLink False Nothi withDirectoryOwnersGroup :: HasCallStack => TestParams -> ChatConfig -> String -> Bool -> Maybe FilePath -> (TestCC -> String -> IO ()) -> IO () withDirectoryOwnersGroup ps cfg dsLink createOwnersGroup webFolder test = do let opts = mkDirectoryOpts ps [KnownContact 2 "alice"] (if createOwnersGroup then Just $ KnownGroup 1 "owners" else Nothing) webFolder - runDirectory cfg opts $ + runDirectory ps cfg opts $ withTestChatCfg ps cfg "super_user" $ \superUser -> do if createOwnersGroup then superUser <## "subscribed 2 connections on server localhost" else superUser <## "subscribed 1 connections on server localhost" test superUser dsLink -runDirectory :: ChatConfig -> DirectoryOpts -> IO () -> IO () -runDirectory cfg opts action = do - t <- forkIO $ directoryService opts cfg +runDirectory :: TestParams -> ChatConfig -> DirectoryOpts -> IO () -> IO () +runDirectory ps cfg opts action = do + t <- forkIO $ directoryService opts $ fst $ testPortsCfg ps cfg testOpts threadDelay 500000 action `finally` killThread t @@ -2393,7 +2395,7 @@ testLinkCheckUpdatesCount ps = do ds ##> "/ad" getContactLink ds True let opts = (mkDirectoryOpts ps [KnownContact 2 "alice"] Nothing Nothing) {linkCheckInterval = 1} - runDirectory testCfg opts $ + runDirectory ps testCfg opts $ withTestChatCfg ps testCfg "super_user" $ \superUser -> do superUser <## "subscribed 1 connections on server localhost" withNewTestChatCfg ps testCfg "bob" bobProfile $ \bob ->