Commit 429d31f7 authored by Dominik Charousset's avatar Dominik Charousset

Add new Robot test for the quote server

parent 38414feb
......@@ -203,6 +203,10 @@ int caf_main(caf::actor_system& sys, const config& cfg) {
});
});
}))
.route("/status", http::method::get,
[](http::responder& res) {
res.respond(http::status::no_content);
})
// --(rst-switch_protocol-end)--
// Run with the configured routes.
.start();
......
......@@ -8,3 +8,12 @@ add_test(
--variable BINARY_PATH:$<TARGET_FILE:rest>
--variable SSL_PATH:${CMAKE_CURRENT_SOURCE_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/http/rest.robot")
add_test(
NAME "robot-web-socket-quote-server"
COMMAND
${Python_EXECUTABLE}
-m robot
--variable BINARY_PATH:$<TARGET_FILE:quote-server>
--variable SSL_PATH:${CMAKE_CURRENT_SOURCE_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/web_socket/quote-server.robot")
obotframework-websocketclient
robotframework
robotframework-requests
......@@ -3,8 +3,8 @@ Documentation A test suite for examples/http/rest.hpp.
Library Process
Library RequestsLibrary
Suite Setup Start Server
Suite Teardown Stop Server
Suite Setup Start Servers
Suite Teardown Stop Servers
*** Variables ***
${HTTP_URL} http://localhost:55501
......@@ -48,7 +48,7 @@ HTTPS Test Delete Key Value Pair
Key Should Not Exist ${HTTPS_URL} foo
*** Keywords ***
Start Server
Start Servers
${res1}= Start Process ${BINARY_PATH} -p 55501
Set Suite Variable ${http_server_process} ${res1}
${res2}= Start Process ${BINARY_PATH} -p 55502 -k ${SSL_PATH}/key.pem -c ${SSL_PATH}/cert.pem
......@@ -56,7 +56,7 @@ Start Server
Wait Until Keyword Succeeds 5s 125ms Check If HTTP Server Is Reachable
Wait Until Keyword Succeeds 5s 125ms Check If HTTPS Server Is Reachable
Stop Server
Stop Servers
Terminate Process ${http_server_process}
Terminate Process ${https_server_process}
......
*** Settings ***
Documentation A test suite for examples/web_socket/quote-server
Library Collections
Library Process
Library RequestsLibrary
Library WebSocketClient
Suite Setup Start Servers
Suite Teardown Stop Servers
*** Variables ***
${HTTP_URL} http://localhost:55501
${HTTPS_URL} https://localhost:55502
${WS_URL} ws://localhost:55501/ws/quotes/seneca
${WSS_URL} wss://localhost:55502/ws/quotes/seneca
${FRAME_COUNT} ${10}
${BINARY_PATH} /path/to/the/server
${SSL_PATH} /path/to/the/pem/files
@{QUOTES} Luck is what happens when preparation meets opportunity.
... All cruelty springs from weakness.
... We suffer more often in imagination than in reality.
... Difficulties strengthen the mind, as labor does the body.
... If a man knows not to which port he sails, no wind is favorable.
... It is the power of the mind to be unconquerable.
... No man was ever wise by chance.
... He suffers more than necessary, who suffers before it is necessary.
... I shall never be ashamed of citing a bad author if the line is good.
... Only time can heal what reason cannot.
*** Test Cases ***
Test WebSocket Server Quotes
[Tags] WebSocket
${fd}= WebSocketClient.Connect ${WS_URL}
${received_strings}= Receive Frames ${fd} ${FRAME_COUNT}
WebSocketClient.Close ${fd}
Validate Frames ${received_strings}
Test WebSocket Over SSL Server Quotes
[Tags] WebSocket
${ssl_arg}= Evaluate {"cert_reqs": ssl.CERT_NONE}
${fd}= WebSocketClient.Connect ${WSS_URL} sslopt=${ssl_arg}
${received_strings}= Receive Frames ${fd} ${FRAME_COUNT}
WebSocketClient.Close ${fd}
Validate Frames ${received_strings}
*** Keywords ***
Start Servers
${res1}= Start Process ${BINARY_PATH} -p 55501
Set Suite Variable ${ws_server_process} ${res1}
${res2}= Start Process ${BINARY_PATH} -p 55502 -k ${SSL_PATH}/key.pem -c ${SSL_PATH}/cert.pem
Set Suite Variable ${wss_server_process} ${res2}
Wait Until Keyword Succeeds 5s 125ms Check If HTTP Server Is Reachable
Wait Until Keyword Succeeds 5s 125ms Check If HTTPS Server Is Reachable
Stop Servers
Terminate Process ${ws_server_process}
Terminate Process ${wss_server_process}
Check If HTTP Server Is Reachable
Log Try reaching ${HTTP_URL}/status.
${resp}= GET ${HTTP_URL}/status expected_status=204
Check If HTTPS Server Is Reachable
Log Try reaching ${HTTPS_URL}/status.
${resp}= GET ${HTTPS_URL}/status expected_status=204 verify=${False}
Receive Frames
[Arguments] ${fd} ${frame_count}
@{received_strings}= Create List
FOR ${i} IN RANGE ${frame_count}
${frame}= WebSocketClient.Recv ${fd}
Append To List ${received_strings} ${frame}
END
[Return] ${received_strings}
Validate Frames
[Arguments] ${received_strings}
Log Received: ${received_strings}.
${count}= Get Length ${received_strings}
Should Be Equal As Integers ${count} ${FRAME_COUNT}
Lists Should Be Equal ${received_strings} ${QUOTES}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment