From 1daae74c6792cd34d147616cb76a0163b8f1e4b0 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Tue, 13 Oct 2020 18:44:40 +0100 Subject: [PATCH] syntax tests for all commands --- tests/SMPClient.hs | 12 ++++-------- tests/Test.hs | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/SMPClient.hs b/tests/SMPClient.hs index da16870c4..ceb37b0af 100644 --- a/tests/SMPClient.hs +++ b/tests/SMPClient.hs @@ -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 diff --git a/tests/Test.hs b/tests/Test.hs index f3d25f1f4..291cee0e7 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -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")]