mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-07-28 18:40:28 +00:00
test: set up and tear down db per test
This commit is contained in:
+129
-129
@@ -16,8 +16,8 @@ testDB = "smp-agent.test.db"
|
||||
|
||||
withStore :: SpecWith SQLiteStore -> Spec
|
||||
withStore =
|
||||
beforeAll (newSQLiteStore testDB)
|
||||
. afterAll (\store -> DB.close (conn store) >> removeFile testDB)
|
||||
before (newSQLiteStore testDB)
|
||||
. after (\store -> DB.close (conn store) >> removeFile testDB)
|
||||
|
||||
storeTests :: Spec
|
||||
storeTests = withStore do
|
||||
@@ -35,54 +35,6 @@ testCreateRcvConn = do
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
rcvId = "1234",
|
||||
rcvPrivateKey = "abcd",
|
||||
sndId = Just "5678",
|
||||
sndKey = Nothing,
|
||||
decryptKey = "dcba",
|
||||
verifyKey = Nothing,
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
createRcvConn store "1" rcvQueue
|
||||
`shouldReturn` Right (ReceiveConnection "1" rcvQueue)
|
||||
getConn store "1"
|
||||
`shouldReturn` Right (SomeConn SCReceive $ ReceiveConnection "1" rcvQueue)
|
||||
let sndQueue =
|
||||
SendQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
sndId = "1234",
|
||||
sndPrivateKey = "abcd",
|
||||
encryptKey = "dcba",
|
||||
signKey = "edcb",
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
addSndQueue store "1" sndQueue
|
||||
`shouldReturn` Right ()
|
||||
getConn store "1"
|
||||
`shouldReturn` Right (SomeConn SCDuplex $ DuplexConnection "1" rcvQueue sndQueue)
|
||||
|
||||
testCreateSndConn :: SpecWith SQLiteStore
|
||||
testCreateSndConn = do
|
||||
it "should create send connection and add receive queue" $ \store -> do
|
||||
let sndQueue =
|
||||
SendQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
sndId = "5678",
|
||||
sndPrivateKey = "abcd",
|
||||
encryptKey = "dcba",
|
||||
signKey = "edcb",
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
createSndConn store "2" sndQueue
|
||||
`shouldReturn` Right (SendConnection "2" sndQueue)
|
||||
getConn store "2"
|
||||
`shouldReturn` Right (SomeConn SCSend $ SendConnection "2" sndQueue)
|
||||
let rcvQueue =
|
||||
ReceiveQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
rcvId = "2345",
|
||||
rcvPrivateKey = "abcd",
|
||||
sndId = Just "2345",
|
||||
sndKey = Nothing,
|
||||
decryptKey = "dcba",
|
||||
@@ -90,83 +42,10 @@ testCreateSndConn = do
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
addRcvQueue store "2" rcvQueue
|
||||
`shouldReturn` Right ()
|
||||
getConn store "2"
|
||||
`shouldReturn` Right (SomeConn SCDuplex $ DuplexConnection "2" rcvQueue sndQueue)
|
||||
|
||||
testAddSndQueue :: SpecWith SQLiteStore
|
||||
testAddSndQueue = do
|
||||
it "should return error on attempts to add send queue to SendConnection or DuplexConnection" $ \store -> do
|
||||
let sndQueue =
|
||||
SendQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
sndId = "6789",
|
||||
sndPrivateKey = "abcd",
|
||||
encryptKey = "dcba",
|
||||
signKey = "edcb",
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
_ <- createSndConn store "3" sndQueue
|
||||
let anotherSndQueue =
|
||||
SendQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
sndId = "7890",
|
||||
sndPrivateKey = "abcd",
|
||||
encryptKey = "dcba",
|
||||
signKey = "edcb",
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
addSndQueue store "3" anotherSndQueue
|
||||
`shouldReturn` Left (SEBadConnType CSend)
|
||||
let rcvQueue =
|
||||
ReceiveQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
rcvId = "6789",
|
||||
rcvPrivateKey = "abcd",
|
||||
sndId = Just "6789",
|
||||
sndKey = Nothing,
|
||||
decryptKey = "dcba",
|
||||
verifyKey = Nothing,
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
_ <- addRcvQueue store "3" rcvQueue
|
||||
addSndQueue store "3" anotherSndQueue
|
||||
`shouldReturn` Left (SEBadConnType CDuplex)
|
||||
|
||||
testAddRcvQueue :: SpecWith SQLiteStore
|
||||
testAddRcvQueue = do
|
||||
it "should return error on attempts to add receive queue to ReceiveConnection or DuplexConnection" $ \store -> do
|
||||
let rcvQueue =
|
||||
ReceiveQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
rcvId = "3456",
|
||||
rcvPrivateKey = "abcd",
|
||||
sndId = Just "3456",
|
||||
sndKey = Nothing,
|
||||
decryptKey = "dcba",
|
||||
verifyKey = Nothing,
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
_ <- createRcvConn store "4" rcvQueue
|
||||
let anotherRcvQueue =
|
||||
ReceiveQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
rcvId = "4567",
|
||||
rcvPrivateKey = "abcd",
|
||||
sndId = Just "4567",
|
||||
sndKey = Nothing,
|
||||
decryptKey = "dcba",
|
||||
verifyKey = Nothing,
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
addRcvQueue store "4" anotherRcvQueue
|
||||
`shouldReturn` Left (SEBadConnType CReceive)
|
||||
createRcvConn store "conn1" rcvQueue
|
||||
`shouldReturn` Right (ReceiveConnection "conn1" rcvQueue)
|
||||
getConn store "conn1"
|
||||
`shouldReturn` Right (SomeConn SCReceive $ ReceiveConnection "conn1" rcvQueue)
|
||||
let sndQueue =
|
||||
SendQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
@@ -177,6 +56,127 @@ testAddRcvQueue = do
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
_ <- addSndQueue store "4" sndQueue
|
||||
addRcvQueue store "4" anotherRcvQueue
|
||||
addSndQueue store "conn1" sndQueue
|
||||
`shouldReturn` Right ()
|
||||
getConn store "conn1"
|
||||
`shouldReturn` Right (SomeConn SCDuplex $ DuplexConnection "conn1" rcvQueue sndQueue)
|
||||
|
||||
testCreateSndConn :: SpecWith SQLiteStore
|
||||
testCreateSndConn = do
|
||||
it "should create send connection and add receive queue" $ \store -> do
|
||||
let sndQueue =
|
||||
SendQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
sndId = "1234",
|
||||
sndPrivateKey = "abcd",
|
||||
encryptKey = "dcba",
|
||||
signKey = "edcb",
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
createSndConn store "conn1" sndQueue
|
||||
`shouldReturn` Right (SendConnection "conn1" sndQueue)
|
||||
getConn store "conn1"
|
||||
`shouldReturn` Right (SomeConn SCSend $ SendConnection "conn1" sndQueue)
|
||||
let rcvQueue =
|
||||
ReceiveQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
rcvId = "2345",
|
||||
rcvPrivateKey = "abcd",
|
||||
sndId = Just "3456",
|
||||
sndKey = Nothing,
|
||||
decryptKey = "dcba",
|
||||
verifyKey = Nothing,
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
addRcvQueue store "conn1" rcvQueue
|
||||
`shouldReturn` Right ()
|
||||
getConn store "conn1"
|
||||
`shouldReturn` Right (SomeConn SCDuplex $ DuplexConnection "conn1" rcvQueue sndQueue)
|
||||
|
||||
testAddSndQueue :: SpecWith SQLiteStore
|
||||
testAddSndQueue = do
|
||||
it "should return error on attempts to add send queue to SendConnection or DuplexConnection" $ \store -> do
|
||||
let sndQueue =
|
||||
SendQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
sndId = "1234",
|
||||
sndPrivateKey = "abcd",
|
||||
encryptKey = "dcba",
|
||||
signKey = "edcb",
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
_ <- createSndConn store "conn1" sndQueue
|
||||
let anotherSndQueue =
|
||||
SendQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
sndId = "2345",
|
||||
sndPrivateKey = "abcd",
|
||||
encryptKey = "dcba",
|
||||
signKey = "edcb",
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
addSndQueue store "conn1" anotherSndQueue
|
||||
`shouldReturn` Left (SEBadConnType CSend)
|
||||
let rcvQueue =
|
||||
ReceiveQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
rcvId = "3456",
|
||||
rcvPrivateKey = "abcd",
|
||||
sndId = Just "4567",
|
||||
sndKey = Nothing,
|
||||
decryptKey = "dcba",
|
||||
verifyKey = Nothing,
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
_ <- addRcvQueue store "conn1" rcvQueue
|
||||
addSndQueue store "conn1" anotherSndQueue
|
||||
`shouldReturn` Left (SEBadConnType CDuplex)
|
||||
|
||||
testAddRcvQueue :: SpecWith SQLiteStore
|
||||
testAddRcvQueue = do
|
||||
it "should return error on attempts to add receive queue to ReceiveConnection or DuplexConnection" $ \store -> do
|
||||
let rcvQueue =
|
||||
ReceiveQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
rcvId = "1234",
|
||||
rcvPrivateKey = "abcd",
|
||||
sndId = Just "2345",
|
||||
sndKey = Nothing,
|
||||
decryptKey = "dcba",
|
||||
verifyKey = Nothing,
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
_ <- createRcvConn store "conn1" rcvQueue
|
||||
let anotherRcvQueue =
|
||||
ReceiveQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
rcvId = "3456",
|
||||
rcvPrivateKey = "abcd",
|
||||
sndId = Just "4567",
|
||||
sndKey = Nothing,
|
||||
decryptKey = "dcba",
|
||||
verifyKey = Nothing,
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
addRcvQueue store "conn1" anotherRcvQueue
|
||||
`shouldReturn` Left (SEBadConnType CReceive)
|
||||
let sndQueue =
|
||||
SendQueue
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
||||
sndId = "5678",
|
||||
sndPrivateKey = "abcd",
|
||||
encryptKey = "dcba",
|
||||
signKey = "edcb",
|
||||
status = New,
|
||||
ackMode = AckMode On
|
||||
}
|
||||
_ <- addSndQueue store "conn1" sndQueue
|
||||
addRcvQueue store "conn1" anotherRcvQueue
|
||||
`shouldReturn` Left (SEBadConnType CDuplex)
|
||||
|
||||
Reference in New Issue
Block a user