core: C API to migrate and check database (#1008)

* core: C API to migrate and check database

* update simplexmq
This commit is contained in:
Evgeny Poberezkin
2022-09-02 16:38:41 +01:00
committed by GitHub
parent 38b3965e68
commit 2b5e3a9459
10 changed files with 71 additions and 18 deletions

View File

@@ -105,14 +105,14 @@ testCfgV1 = testCfg {agentConfig = testAgentCfgV1}
createTestChat :: ChatConfig -> ChatOpts -> String -> Profile -> IO TestCC
createTestChat cfg opts@ChatOpts {dbKey} dbPrefix profile = do
let dbFilePrefix = testDBPrefix <> dbPrefix
st <- createStore (dbFilePrefix <> "_chat.db") dbKey False
st <- createChatStore (dbFilePrefix <> "_chat.db") dbKey False
Right user <- withTransaction st $ \db -> runExceptT $ createUser db profile True
startTestChat_ st cfg opts dbFilePrefix user
startTestChat :: ChatConfig -> ChatOpts -> String -> IO TestCC
startTestChat cfg opts@ChatOpts {dbKey} dbPrefix = do
let dbFilePrefix = testDBPrefix <> dbPrefix
st <- createStore (dbFilePrefix <> "_chat.db") dbKey False
st <- createChatStore (dbFilePrefix <> "_chat.db") dbKey False
Just user <- find activeUser <$> withTransaction st getUsers
startTestChat_ st cfg opts dbFilePrefix user

View File

@@ -73,7 +73,9 @@ parsedMarkdown = "{\"formattedText\":[{\"format\":{\"type\":\"bold\"},\"text\":\
testChatApiNoUser :: IO ()
testChatApiNoUser = withTmpFiles $ do
DBMOk <- chatMigrateDB testDBPrefix ""
cc <- chatInit testDBPrefix
DBMErrorNotADatabase _ <- chatMigrateDB testDBPrefix "myKey"
chatSendCmd cc "/u" `shouldReturn` noActiveUser
chatSendCmd cc "/_start" `shouldReturn` noActiveUser
chatSendCmd cc "/u alice Alice" `shouldReturn` activeUser
@@ -81,10 +83,14 @@ testChatApiNoUser = withTmpFiles $ do
testChatApi :: IO ()
testChatApi = withTmpFiles $ do
let f = chatStoreFile $ testDBPrefix <> "1"
st <- createStore f "" True
let dbPrefix = testDBPrefix <> "1"
f = chatStoreFile dbPrefix
st <- createChatStore f "myKey" True
Right _ <- withTransaction st $ \db -> runExceptT $ createUser db aliceProfile True
cc <- chatInit $ testDBPrefix <> "1"
DBMOk <- chatMigrateDB testDBPrefix "myKey"
cc <- chatInitKey dbPrefix "myKey"
DBMErrorNotADatabase _ <- chatMigrateDB testDBPrefix ""
DBMErrorNotADatabase _ <- chatMigrateDB testDBPrefix "anotherKey"
chatSendCmd cc "/u" `shouldReturn` activeUser
chatSendCmd cc "/u alice Alice" `shouldReturn` activeUserExists
chatSendCmd cc "/_start" `shouldReturn` chatStarted

View File

@@ -5,7 +5,7 @@ module SchemaDump where
import ChatClient (withTmpFiles)
import Control.DeepSeq
import Control.Monad (void)
import Simplex.Chat.Store (createStore)
import Simplex.Chat.Store (createChatStore)
import System.Process (readCreateProcess, shell)
import Test.Hspec
@@ -22,7 +22,7 @@ schemaDumpTest =
testVerifySchemaDump :: IO ()
testVerifySchemaDump =
withTmpFiles $ do
void $ createStore testDB "" False
void $ createChatStore testDB "" False
void $ readCreateProcess (shell $ "touch " <> schema) ""
savedSchema <- readFile schema
savedSchema `deepseq` pure ()