syntax tests for all commands

This commit is contained in:
Evgeny Poberezkin 2020-10-13 18:44:40 +01:00
parent 00f61c1f68
commit 1daae74c67
2 changed files with 24 additions and 13 deletions

View File

@ -37,16 +37,12 @@ testHost = "localhost"
type TestTransmission = (Signature, ConnId, String)
smpServerTest :: [TestTransmission] -> IO [TestTransmission]
smpServerTest toSend =
smpServerTest commands =
E.bracket
(forkIO $ runSMPServer testPort)
killThread
\_ -> runSMPClient
"localhost"
testPort
\h -> mapM (sendReceive h) toSend
\_ -> runSMPClient "localhost" testPort $
\h -> mapM (sendReceive h) commands
where
sendReceive :: Handle -> TestTransmission -> IO TestTransmission
sendReceive h t = do
tPutRaw h t
tGetRaw h
sendReceive h t = tPutRaw h t >> tGetRaw h

View File

@ -15,11 +15,11 @@ main = hspec do
it "many parameters" $ [("", "", "CREATE 1 2")] >#> [("", "", "ERROR SYNTAX 2")]
it "has signature" $ [("123", "", "CREATE 123")] >#> [("", "", "ERROR SYNTAX 4")]
it "connection ID" $ [("", "1", "CREATE 123")] >#> [("", "1", "ERROR SYNTAX 4")]
describe "SUB" do
it "valid syntax" $ [("123", "1", "SUB")] >#> [("", "1", "ERROR AUTH")]
it "parameters" $ [("123", "1", "SUB 1")] >#> [("", "1", "ERROR SYNTAX 2")]
it "no signature" $ [("", "1", "SUB")] >#> [("", "1", "ERROR SYNTAX 3")]
it "no connection ID" $ [("123", "", "SUB")] >#> [("", "", "ERROR SYNTAX 3")]
noParamsSyntaxTest "SUB"
oneParamSyntaxTest "SECURE"
oneParamSyntaxTest "DELMSG"
noParamsSyntaxTest "SUSPEND"
noParamsSyntaxTest "DELETE"
describe "SEND" do
it "valid syntax 1" $ [("123", "1", "SEND :hello")] >#> [("", "1", "OK")]
it "valid syntax 2" $ [("123", "1", "SEND 11\nhello there\n")] >#> [("", "1", "OK")]
@ -30,3 +30,18 @@ main = hspec do
it "bigger body" $ [("123", "1", "SEND 4\nhello\n")] >#> [("", "1", "ERROR SYNTAX 7")]
describe "broker response not allowed" do
it "OK" $ [("123", "1", "OK")] >#> [("", "1", "ERROR SYNTAX 8")]
noParamsSyntaxTest :: String -> SpecWith ()
noParamsSyntaxTest cmd = describe cmd do
it "valid syntax" $ [("123", "1", cmd)] >#> [("", "1", "ERROR AUTH")]
it "parameters" $ [("123", "1", cmd ++ " 1")] >#> [("", "1", "ERROR SYNTAX 2")]
it "no signature" $ [("", "1", cmd)] >#> [("", "1", "ERROR SYNTAX 3")]
it "no connection ID" $ [("123", "", cmd)] >#> [("", "", "ERROR SYNTAX 3")]
oneParamSyntaxTest :: String -> SpecWith ()
oneParamSyntaxTest cmd = describe cmd do
it "valid syntax" $ [("123", "1", cmd ++ " 456")] >#> [("", "1", "ERROR AUTH")]
it "no parameters" $ [("123", "1", cmd)] >#> [("", "1", "ERROR SYNTAX 2")]
it "many parameters" $ [("123", "1", cmd ++ " 1 2")] >#> [("", "1", "ERROR SYNTAX 2")]
it "no signature" $ [("", "1", cmd ++ " 456")] >#> [("", "1", "ERROR SYNTAX 3")]
it "no connection ID" $ [("123", "", cmd ++ " 456")] >#> [("", "", "ERROR SYNTAX 3")]