From 380eed57d935ef227026aba32f8239a8dca7b0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Hurtado?= Date: Tue, 20 Aug 2019 10:31:14 +0200 Subject: [PATCH] Added features for append/error_malformed, delete/list_order, insert/error_malformed and insert/list_order. Updated append/error_unprocessable and list/success. --- .../control/append/error_malformed.feature | 24 ++++++ .../append/error_unprocessable.feature | 4 +- .../control/delete/list_order.feature | 65 ++++++++++++++++ .../control/insert/error_malformed.feature | 25 +++++++ .../insert/error_unprocessable.feature | 2 - .../control/insert/list_order.feature | 75 +++++++++++++++++++ .../features/control/list/success.feature | 8 +- 7 files changed, 196 insertions(+), 7 deletions(-) diff --git a/spec/test/features/control/append/error_malformed.feature b/spec/test/features/control/append/error_malformed.feature index e69de29..dbe2d31 100644 --- a/spec/test/features/control/append/error_malformed.feature +++ b/spec/test/features/control/append/error_malformed.feature @@ -0,0 +1,24 @@ +Feature: Kapow! server reject responses with malformed JSON bodies. + Kapow! server will reject to append a route when + it receives a malformed json document in the + request body. + + Scenario: Error because a malformed JSON document. + If a request comes with an invalid JSON document + the server will respond with a bad request error. + + Given I have a running Kapow! server + When I try to append with this JSON document: + """ + { + "method" "GET", + "url_pattern": /hello, + "entrypoint": null + "command": "echo Hello + World | response /body", + "id": "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" + } + """ + Then I get 400 as response code + And I get "Malformed JSON" as response phrase + And I get an empty response body diff --git a/spec/test/features/control/append/error_unprocessable.feature b/spec/test/features/control/append/error_unprocessable.feature index 6805625..5fbb274 100644 --- a/spec/test/features/control/append/error_unprocessable.feature +++ b/spec/test/features/control/append/error_unprocessable.feature @@ -1,5 +1,5 @@ Feature: Kapow! server reject responses with semantic errors. - Kapow! server will reject to create routes when + Kapow! server will reject to append routes when it receives a valid json document but not conforming with the specification. @@ -41,5 +41,3 @@ Feature: Kapow! server reject responses with semantic errors. Then I get unprocessable entity as response code And I get "Invalid Data Type" as response phrase And I get an empty response body - -... diff --git a/spec/test/features/control/delete/list_order.feature b/spec/test/features/control/delete/list_order.feature index e69de29..eec9ecc 100644 --- a/spec/test/features/control/delete/list_order.feature +++ b/spec/test/features/control/delete/list_order.feature @@ -0,0 +1,65 @@ +Feature: Routes auto-ordering in a Kapow! server. + + When deleting routes the server will mantain the + remaining routes ordered an with consecutive indexes. + + Background: + Given I have a Kapow! server whith the following routes: + | method | url_pattern | entrypoint | command | + | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | + | GET | /listEtcDir | /bin/sh -c | ls -la /etc \| response /body | + | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | + + Scenario: Removing the first routes. + When removing the first route the remaining ones + will maintain their relative order and their indexes + will be decreased by one. + + When I delete the first route inserted + Then I get 200 as response code + And I get "OK" as response phrase + And I get an empty response body + When I request a routes listing + Then I get 200 as response code + And I get "OK" as response phrase + And I get a list with the following elements: + | method | url_pattern | entrypoint | command | Index | id | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | 0 | * | + | GET | /listEtcDir | /bin/sh -c | ls -la /etc \| response /body | 1 | * | + | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | 2 | * | + + Scenario: Removing the last routes. + When removing the last route the remaining ones will + maintain their relative order and indexes. + + When I delete the last route inserted + Then I get 200 as response code + And I get "OK" as response phrase + And I get an empty response body + When I request a routes listing + Then I get 200 as response code + And I get "OK" as response phrase + And I get a list with the following elements: + | method | url_pattern | entrypoint | command | Index | id | + | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | * | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | 1 | * | + | GET | /listEtcDir | /bin/sh -c | ls -la /etc \| response /body | 2 | * | + + Scenario: Removing a midst route. + When removing a midst route the remaining ones will + maintain their relative order and the indexes of the + following routes will be decreased by one. + + When I delete the second route inserted + Then I get 200 as response code + And I get "OK" as response phrase + And I get an empty response body + When I request a routes listing + Then I get 200 as response code + And I get "OK" as response phrase + And I get a list with the following elements: + | method | url_pattern | entrypoint | command | Index | id | + | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | * | + | GET | /listEtcDir | /bin/sh -c | ls -la /etc \| response /body | 1 | * | + | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | 2 | * | diff --git a/spec/test/features/control/insert/error_malformed.feature b/spec/test/features/control/insert/error_malformed.feature index e69de29..10f82ea 100644 --- a/spec/test/features/control/insert/error_malformed.feature +++ b/spec/test/features/control/insert/error_malformed.feature @@ -0,0 +1,25 @@ +Feature: Kapow! server reject responses with malformed JSON bodies. + Kapow! server will reject to insert a route when + it receives a malformed json document in the + request body. + + Scenario: Error because a malformed JSON document. + If a request comes with an invalid JSON document + the server will respond with a bad request error. + + Given I have a running Kapow! server + When I try to insert with this JSON document: + """ + { + "method" "GET", + "url_pattern": /hello, + "entrypoint": null + "command": "echo Hello + World | response /body", + "index": 0, + "id": "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" + } + """ + Then I get bad request as response code + And I get "Malformed JSON" as response phrase + And I get an empty response body diff --git a/spec/test/features/control/insert/error_unprocessable.feature b/spec/test/features/control/insert/error_unprocessable.feature index 9b01557..df1cba9 100644 --- a/spec/test/features/control/insert/error_unprocessable.feature +++ b/spec/test/features/control/insert/error_unprocessable.feature @@ -40,5 +40,3 @@ Feature: Kapow! server reject insert responses with semantic errors. Then I get unprocessable entity as response code And I get "Invalid Data Type" as response phrase And I get an empty response body - -... diff --git a/spec/test/features/control/insert/list_order.feature b/spec/test/features/control/insert/list_order.feature index e69de29..b3b63f1 100644 --- a/spec/test/features/control/insert/list_order.feature +++ b/spec/test/features/control/insert/list_order.feature @@ -0,0 +1,75 @@ +Feature: Routes auto-ordering in a Kapow! server. + + When inserting routes the server will mantain the + whole set of routes ordered an with consecutive indexes. + + Background: + Given I have a Kapow! server whith the following routes: + | method | url_pattern | entrypoint | command | + | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | + | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | + + Scenario: Inserting before the first route. + When inserting before the first route the previous set + will maintain their relative order and their indexes + will be increased by one. + + When I insert the route: + | method | url_pattern | entrypoint | command | index | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | 0 | + Then I get 200 as response code + And I get "OK" as response phrase + And I get the following entity as response body: + | method | url_pattern | entrypoint | command | index | id | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | 0 | * | + When I request a routes listing + Then I get 200 as response code + And I get "OK" as response phrase + And I get a list with the following elements: + | method | url_pattern | entrypoint | command | Index | id | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | 0 | * | + | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 1 | * | + | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | 2 | * | + + Scenario: Inserting after the last routes. + When inserting after the last route the previous set + will maintain their relative order and indexes. + + When I insert the route: + | method | url_pattern | entrypoint | command | index | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | 2 | + Then I get 200 as response code + And I get "OK" as response phrase + And I get the following entity as response body: + | method | url_pattern | entrypoint | command | index | id | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | 2 | * | + When I request a routes listing + Then I get 200 as response code + And I get "OK" as response phrase + And I get a list with the following elements: + | method | url_pattern | entrypoint | command | Index | id | + | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | * | + | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | 1 | * | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | 2 | * | + + Scenario: Inserting a midst route. + When inserting a midst route the previous route set + will maintain their relative order and the indexes + of thefollowing routes will be increased by one. + + When I insert the route: + | method | url_pattern | entrypoint | command | index | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | 1 | + Then I get 200 as response code + And I get "OK" as response phrase + And I get the following entity as response body: + | method | url_pattern | entrypoint | command | index | id | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | 1 | * | + When I request a routes listing + Then I get 200 as response code + And I get "OK" as response phrase + And I get a list with the following elements: + | method | url_pattern | entrypoint | command | Index | id | + | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | * | + | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | 1 | * | + | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | 2 | * | diff --git a/spec/test/features/control/list/success.feature b/spec/test/features/control/list/success.feature index aaa40e9..8b2c423 100644 --- a/spec/test/features/control/list/success.feature +++ b/spec/test/features/control/list/success.feature @@ -10,7 +10,9 @@ Feature: Listing routes in a Kapow! server Given I have a just started Kapow! server When I request a routes listing - Then I get an empty list + Then I get 200 as response code + And I get "OK" as response phrase + And I get an empty list Scenario: Listing routes on a server with routes loaded. After some route creation/insertion operations the server @@ -21,7 +23,9 @@ Feature: Listing routes in a Kapow! server | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | When I request a routes listing - Then I get a list with the following elements: + Then I get 200 as response code + And I get "OK" as response phrase + And I get a list with the following elements: | method | url_pattern | entrypoint | command | index | id | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | * | | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | 1 | * |