From e4771de5ed9ddcb28dd0e7aa13ac65412dc3a733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Abdelkader=20Mart=C3=ADnez=20P=C3=A9rez?= Date: Fri, 16 Aug 2019 17:19:19 +0200 Subject: [PATCH 1/7] Implement non-interactive mode. Add -i/--interactive flag. --- poc/bin/kapow | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/poc/bin/kapow b/poc/bin/kapow index 9836dfd..cf01e47 100755 --- a/poc/bin/kapow +++ b/poc/bin/kapow @@ -306,7 +306,7 @@ def delete_route(app): ######################################################################## -async def run_init_script(app, scripts): +async def run_init_script(app, scripts, interactive): """ Run the init script if given, then wait for the shell to finish. @@ -320,7 +320,10 @@ async def run_init_script(app, scripts): yield shlex.quote(filename) yield "<(echo)" filenames = " ".join(build_filenames()) - cmd = f"/bin/bash --init-file <(cat {filenames})" + if interactive: + cmd = f"/bin/bash --init-file <(cat {filenames})" + else: + cmd = f"/bin/bash <(cat {filenames})" shell_task = await asyncio.create_subprocess_shell( cmd, @@ -330,16 +333,17 @@ async def run_init_script(app, scripts): }) await shell_task.wait() - await app.cleanup() - os._exit(shell_task.returncode) + if interactive: + await app.cleanup() + os._exit(shell_task.returncode) async def start_background_tasks(app): global loop - app["debug_tasks"] = loop.create_task(run_init_script(app, app["scripts"])) + app["debug_tasks"] = loop.create_task(run_init_script(app, app["scripts"], app["interactive"])) -async def start_kapow_server(bind, scripts, certfile=None, keyfile=None): +async def start_kapow_server(bind, scripts, certfile=None, interactive=False, keyfile=None): user_app = web.Application(client_max_size=1024**3) user_runner = web.AppRunner(user_app) await user_runner.setup() @@ -366,6 +370,7 @@ async def start_kapow_server(bind, scripts, certfile=None, keyfile=None): web.put('/handlers/{id}/{field:.*}', set_field), ]) control_app["scripts"] = scripts + control_app["interactive"] = interactive control_app.on_startup.append(start_background_tasks) control_runner = web.AppRunner(control_app) @@ -391,12 +396,15 @@ def kapow(ctx): @click.option("--certfile", default=None) @click.option("--keyfile", default=None) @click.option("--bind", default="0.0.0.0:8080") +@click.option("-i", "--interactive", is_flag=True) @click.argument("scripts", nargs=-1) -def server(certfile, keyfile, bind, scripts): +def server(certfile, keyfile, bind, interactive, scripts): if bool(certfile) ^ bool(keyfile): print("For SSL both 'certfile' and 'keyfile' should be provided.") sys.exit(1) - loop.run_until_complete(start_kapow_server(bind, scripts, certfile, keyfile)) + if not scripts: + interactive = True + loop.run_until_complete(start_kapow_server(bind, scripts, certfile, interactive, keyfile)) loop.run_forever() @kapow.group() From 5352322ad5f54158c3996c373194df0f7e0648b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Abdelkader=20Mart=C3=ADnez=20P=C3=A9rez?= Date: Tue, 20 Aug 2019 08:22:48 +0200 Subject: [PATCH 2/7] Adapting style to the capabilities of gherkin-lint. --- spec/test/.gherkin-lintrc | 6 ++--- .../append/error_unprocessable.feature | 26 +++++++++---------- .../features/control/append/success.feature | 16 ++++++------ .../control/delete/error_notfound.feature | 4 +-- .../features/control/delete/success.feature | 6 ++--- .../insert/error_unprocessable.feature | 26 +++++++++---------- .../features/control/insert/success.feature | 16 ++++++------ .../features/control/list/success.feature | 14 +++++----- 8 files changed, 55 insertions(+), 59 deletions(-) diff --git a/spec/test/.gherkin-lintrc b/spec/test/.gherkin-lintrc index 108e70e..9c5c061 100644 --- a/spec/test/.gherkin-lintrc +++ b/spec/test/.gherkin-lintrc @@ -12,8 +12,8 @@ "Scenario": 2, "Background": 2, "given": 4, - "when": 6, - "then": 6, + "when": 4, + "then": 4, "and": 6, "but": 6, "example": 2, @@ -24,7 +24,7 @@ "new-line-at-eof": ["on", "yes"], "no-multiple-empty-lines": "on", "no-scenario-outlines-without-examples": "on", - "name-length": ["on", {"Feature": 50}], + "name-length": ["on", {"Feature": 80}], "no-restricted-tags": ["on", {"tags": ["@watch", "@wip"]}], "use-and": "on", "no-duplicate-tags": "on", diff --git a/spec/test/features/control/append/error_unprocessable.feature b/spec/test/features/control/append/error_unprocessable.feature index 6805625..861cf9e 100644 --- a/spec/test/features/control/append/error_unprocessable.feature +++ b/spec/test/features/control/append/error_unprocessable.feature @@ -9,10 +9,10 @@ Feature: Kapow! server reject responses with semantic errors. missing fields. Given I have a running Kapow! server - When I append the route: - | entrypoint | command | - | /bin/sh -c | ls -la / \| response /body | - Then I get unprocessable entity as response code + When I append the route: + | entrypoint | command | + | /bin/sh -c | ls -la / \| response /body | + Then I get unprocessable entity as response code And I get "Missing Mandatory Field" as response phrase And I get the following entity as response body: | missing_mandatory_fields | @@ -23,10 +23,10 @@ Feature: Kapow! server reject responses with semantic errors. field url_pattern the server responds with an error. Given I have a running Kapow! server - When I append the route: - | method | url_pattern | entrypoint | command | - | GET | +123-- | /bin/sh -c | ls -la / \| response /body | - Then I get unprocessable entity as response code + When I append the route: + | method | url_pattern | entrypoint | command | + | GET | +123-- | /bin/sh -c | ls -la / \| response /body | + Then I get unprocessable entity as response code And I get "Invalid Route Spec" as response phrase And I get an empty response body @@ -35,11 +35,9 @@ Feature: Kapow! server reject responses with semantic errors. field method the server responds with an error. Given I have a running Kapow! server - When I append the route: - | method | url_pattern | entrypoint | command | - | AVECES | +123-- | /bin/sh -c | ls -la / \| response /body | - Then I get unprocessable entity as response code + When I append the route: + | method | url_pattern | entrypoint | command | + | AVECES | +123-- | /bin/sh -c | ls -la / \| response /body | + 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/append/success.feature b/spec/test/features/control/append/success.feature index ab44a07..127f52c 100644 --- a/spec/test/features/control/append/success.feature +++ b/spec/test/features/control/append/success.feature @@ -8,10 +8,10 @@ Feature: Append new routes in Kapow! server. will be at index 0. Given I have a just started Kapow! server - When I append the route: - | method | url_pattern | entrypoint | command | - | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | - Then I get created as response code + When I append the route: + | method | url_pattern | entrypoint | command | + | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | + Then I get created as response code And I get "Created" as response phrase And I get the following entity as response body: | method | url_pattern | entrypoint | command | index | id | @@ -25,10 +25,10 @@ Feature: Append new routes in Kapow! server. | 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 | - When I append the route: - | method | url_pattern | entrypoint | command | - | GET | /listEtcDir | /bin/sh -c | ls -la /etc \| response /body | - Then I get created as response code + When I append the route: + | method | url_pattern | entrypoint | command | + | GET | /listEtcDir | /bin/sh -c | ls -la /etc \| response /body | + Then I get created as response code And I get "Created" as response phrase And I get the following entity as response body: | method | url_pattern | entrypoint | command | index | id | diff --git a/spec/test/features/control/delete/error_notfound.feature b/spec/test/features/control/delete/error_notfound.feature index 8a0caa7..26423af 100644 --- a/spec/test/features/control/delete/error_notfound.feature +++ b/spec/test/features/control/delete/error_notfound.feature @@ -7,7 +7,7 @@ Feature: Fail to delete a route in Kapow! server. will trigger a not found error. Given I have a just started Kapow! server - When I delete the route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" - Then I get not found as response code + When I delete the route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" + Then I get not found as response code And I get "Not Found" as response phrase And I get an empty response body diff --git a/spec/test/features/control/delete/success.feature b/spec/test/features/control/delete/success.feature index fc31272..dc9dcc7 100644 --- a/spec/test/features/control/delete/success.feature +++ b/spec/test/features/control/delete/success.feature @@ -6,8 +6,8 @@ Feature: Delete routes in Kapow! server. Routes are removed from the sever by specifying their id. Given I have a running Kapow! server - And It has a route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" - When I delete the route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" - Then I get ok as response code + And It has a route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" + When I delete the route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" + Then I get ok as response code And I get "OK" 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..58c2027 100644 --- a/spec/test/features/control/insert/error_unprocessable.feature +++ b/spec/test/features/control/insert/error_unprocessable.feature @@ -8,10 +8,10 @@ Feature: Kapow! server reject insert responses with semantic errors. missing fields. Given I have a running Kapow! server - When I insert the route: - | entrypoint | command | - | /bin/sh -c | ls -la / \| response /body | - Then I get unprocessable entity as response code + When I insert the route: + | entrypoint | command | + | /bin/sh -c | ls -la / \| response /body | + Then I get unprocessable entity as response code And I get "Missing Mandatory Field" as response phrase And I get the following entity as response body: | missing_mandatory_fields | @@ -22,10 +22,10 @@ Feature: Kapow! server reject insert responses with semantic errors. url_pattern field the server responds with an error. Given I have a running Kapow! server - When I insert the route: - | method | url_pattern | entrypoint | command | index | - | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | - Then I get unprocessable entity as response code + When I insert the route: + | method | url_pattern | entrypoint | command | index | + | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | + Then I get unprocessable entity as response code And I get "Invalid Route Spec" as response phrase And I get an empty response body @@ -34,11 +34,9 @@ Feature: Kapow! server reject insert responses with semantic errors. method field the server responds with an error. Given I have a running Kapow! server - When I insert the route: - | method | url_pattern | entrypoint | command | index | - | AVECES | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | - Then I get unprocessable entity as response code + When I insert the route: + | method | url_pattern | entrypoint | command | index | + | AVECES | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | + 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/success.feature b/spec/test/features/control/insert/success.feature index 4a2f2ff..06016c7 100644 --- a/spec/test/features/control/insert/success.feature +++ b/spec/test/features/control/insert/success.feature @@ -13,10 +13,10 @@ Feature: Insert new routes in Kapow! server. A route can be inserted at the begining of the list by specifying an index 0 in the request. - When I insert the route: - | method | url_pattern | entrypoint | command | index | - | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | - Then I get ok as response code + When I insert the route: + | method | url_pattern | entrypoint | command | index | + | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | + Then I get ok 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 | @@ -27,10 +27,10 @@ Feature: Insert new routes in Kapow! server. by specifying an index less or equal to the last index in the request. - When I insert the route: - | method | url_pattern | entrypoint | command | index | - | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 1 | - Then I get ok as response code + When I insert the route: + | method | url_pattern | entrypoint | command | index | + | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 1 | + Then I get ok 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 | diff --git a/spec/test/features/control/list/success.feature b/spec/test/features/control/list/success.feature index aaa40e9..ddd8439 100644 --- a/spec/test/features/control/list/success.feature +++ b/spec/test/features/control/list/success.feature @@ -9,8 +9,8 @@ Feature: Listing routes in a Kapow! server will show an empty list of routes. Given I have a just started Kapow! server - When I request a routes listing - Then I get an empty list + When I request a routes listing + Then I get an empty list Scenario: Listing routes on a server with routes loaded. After some route creation/insertion operations the server @@ -20,8 +20,8 @@ Feature: Listing routes in a Kapow! server | 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 | - When I request a routes listing - Then 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 | * | + When I request a routes listing + Then 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 | * | From 5e253c9814b293bbd8a8dc0b75ca4f26e764502e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Abdelkader=20Mart=C3=ADnez=20P=C3=A9rez?= Date: Tue, 20 Aug 2019 09:54:18 +0200 Subject: [PATCH 3/7] Change response code from phrase to code and 'phrase' by 'reason phrase' --- .../append/error_unprocessable.feature | 12 ++--- .../features/control/append/success.feature | 8 +-- .../control/delete/error_notfound.feature | 4 +- .../features/control/delete/success.feature | 4 +- .../insert/error_unprocessable.feature | 12 ++--- .../features/control/insert/success.feature | 8 +-- spec/test/features/steps/steps.py | 49 +++++++++++++++++++ 7 files changed, 73 insertions(+), 24 deletions(-) diff --git a/spec/test/features/control/append/error_unprocessable.feature b/spec/test/features/control/append/error_unprocessable.feature index 861cf9e..07dedaa 100644 --- a/spec/test/features/control/append/error_unprocessable.feature +++ b/spec/test/features/control/append/error_unprocessable.feature @@ -12,8 +12,8 @@ Feature: Kapow! server reject responses with semantic errors. When I append the route: | entrypoint | command | | /bin/sh -c | ls -la / \| response /body | - Then I get unprocessable entity as response code - And I get "Missing Mandatory Field" as response phrase + Then I get 422 as response code + And I get "Missing Mandatory Field" as response reason phrase And I get the following entity as response body: | missing_mandatory_fields | | "url_pattern", "method" | @@ -26,8 +26,8 @@ Feature: Kapow! server reject responses with semantic errors. When I append the route: | method | url_pattern | entrypoint | command | | GET | +123-- | /bin/sh -c | ls -la / \| response /body | - Then I get unprocessable entity as response code - And I get "Invalid Route Spec" as response phrase + Then I get 422 as response code + And I get "Invalid Route Spec" as response reason phrase And I get an empty response body Scenario: Error because of wrong method value. @@ -38,6 +38,6 @@ Feature: Kapow! server reject responses with semantic errors. When I append the route: | method | url_pattern | entrypoint | command | | AVECES | +123-- | /bin/sh -c | ls -la / \| response /body | - Then I get unprocessable entity as response code - And I get "Invalid Data Type" as response phrase + Then I get 422 as response code + And I get "Invalid Data Type" as response reason phrase And I get an empty response body diff --git a/spec/test/features/control/append/success.feature b/spec/test/features/control/append/success.feature index 127f52c..a048b17 100644 --- a/spec/test/features/control/append/success.feature +++ b/spec/test/features/control/append/success.feature @@ -11,8 +11,8 @@ Feature: Append new routes in Kapow! server. When I append the route: | method | url_pattern | entrypoint | command | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | - Then I get created as response code - And I get "Created" as response phrase + Then I get 201 as response code + And I get "Created" as response reason phrase And I get the following entity as response body: | method | url_pattern | entrypoint | command | index | id | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | * | @@ -28,8 +28,8 @@ Feature: Append new routes in Kapow! server. When I append the route: | method | url_pattern | entrypoint | command | | GET | /listEtcDir | /bin/sh -c | ls -la /etc \| response /body | - Then I get created as response code - And I get "Created" as response phrase + Then I get 201 as response code + And I get "Created" as response reason phrase And I get the following entity as response body: | method | url_pattern | entrypoint | command | index | id | | GET | /listEtcDir | /bin/sh -c | ls -la /etc \| response /body | 2 | * | diff --git a/spec/test/features/control/delete/error_notfound.feature b/spec/test/features/control/delete/error_notfound.feature index 26423af..81ddedd 100644 --- a/spec/test/features/control/delete/error_notfound.feature +++ b/spec/test/features/control/delete/error_notfound.feature @@ -8,6 +8,6 @@ Feature: Fail to delete a route in Kapow! server. Given I have a just started Kapow! server When I delete the route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" - Then I get not found as response code - And I get "Not Found" as response phrase + Then I get 404 as response code + And I get "Not Found" as response reason phrase And I get an empty response body diff --git a/spec/test/features/control/delete/success.feature b/spec/test/features/control/delete/success.feature index dc9dcc7..09522c3 100644 --- a/spec/test/features/control/delete/success.feature +++ b/spec/test/features/control/delete/success.feature @@ -8,6 +8,6 @@ Feature: Delete routes in Kapow! server. Given I have a running Kapow! server And It has a route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" When I delete the route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" - Then I get ok as response code - And I get "OK" as response phrase + Then I get 200 as response code + And I get "OK" as response reason 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 58c2027..2600f15 100644 --- a/spec/test/features/control/insert/error_unprocessable.feature +++ b/spec/test/features/control/insert/error_unprocessable.feature @@ -11,8 +11,8 @@ Feature: Kapow! server reject insert responses with semantic errors. When I insert the route: | entrypoint | command | | /bin/sh -c | ls -la / \| response /body | - Then I get unprocessable entity as response code - And I get "Missing Mandatory Field" as response phrase + Then I get 422 as response code + And I get "Missing Mandatory Field" as response reason phrase And I get the following entity as response body: | missing_mandatory_fields | | "url_pattern", "method" | @@ -25,8 +25,8 @@ Feature: Kapow! server reject insert responses with semantic errors. When I insert the route: | method | url_pattern | entrypoint | command | index | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | - Then I get unprocessable entity as response code - And I get "Invalid Route Spec" as response phrase + Then I get 422 as response code + And I get "Invalid Route Spec" as response reason phrase And I get an empty response body Scenario: Error because of wrong method value. @@ -37,6 +37,6 @@ Feature: Kapow! server reject insert responses with semantic errors. When I insert the route: | method | url_pattern | entrypoint | command | index | | AVECES | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | - Then I get unprocessable entity as response code - And I get "Invalid Data Type" as response phrase + Then I get 422 as response code + And I get "Invalid Data Type" as response reason phrase And I get an empty response body diff --git a/spec/test/features/control/insert/success.feature b/spec/test/features/control/insert/success.feature index 06016c7..35775ab 100644 --- a/spec/test/features/control/insert/success.feature +++ b/spec/test/features/control/insert/success.feature @@ -16,8 +16,8 @@ Feature: Insert new routes in Kapow! server. When I insert the route: | method | url_pattern | entrypoint | command | index | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | - Then I get ok as response code - And I get "OK" as response phrase + Then I get 200 as response code + And I get "OK" as response reason phrase And I get the following entity as response body: | method | url_pattern | entrypoint | command | index | id | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 0 | * | @@ -30,8 +30,8 @@ Feature: Insert new routes in Kapow! server. When I insert the route: | method | url_pattern | entrypoint | command | index | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 1 | - Then I get ok as response code - And I get "OK" as response phrase + Then I get 200 as response code + And I get "OK" as response reason phrase And I get the following entity as response body: | method | url_pattern | entrypoint | command | index | id | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | 1 | * | diff --git a/spec/test/features/steps/steps.py b/spec/test/features/steps/steps.py index 6a9156f..bb73e67 100644 --- a/spec/test/features/steps/steps.py +++ b/spec/test/features/steps/steps.py @@ -17,6 +17,7 @@ class Env(EnvironConfig): @given('I have a just started Kapow! server') +@given('I have a running Kapow! server') def step_impl(context): context.server = subprocess.Popen( Env.KAPOW_SERVER_CMD, @@ -69,3 +70,51 @@ def step_impl(context): assert header in entry, f"Response does not contain the key {header}" if row[header] != '*': assert entry[header] == row[header], f"Values mismatch" + +# +# +# + +@when('I append the route') +def step_impl(context): + if not hasattr(context, 'table'): + raise RuntimeError("A table must be set for this step.") + + for row in context.table: + response = requests.post(f"{Env.KAPOW_CONTROLAPI_URL}/routes", + json={h: row[h] for h in row.headings}) + response.raise_for_status() + + +@then('I get {code} as response code') +def step_impl(context, code): + raise NotImplementedError('STEP: Then I get unprocessable entity as response code') + + +@then('I get "{reason}" as response reason phrase') +def step_impl(context, reason): + raise NotImplementedError('STEP: Then I get "Missing Mandatory Field" as response phrase') + + +@then('I get the following entity as response body') +def step_impl(context): + raise NotImplementedError('STEP: Then I get the following entity as response body') + + +@then('I get an empty response body') +def step_impl(context): + raise NotImplementedError('STEP: Then I get an empty response body') + + +@when('I delete the route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"') +def step_impl(context): + raise NotImplementedError('STEP: When I delete the route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"') + + +@given('It has a route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"') +def step_impl(context): + raise NotImplementedError('STEP: Given It has a route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"') + +@when('I insert the route') +def step_impl(context): + raise NotImplementedError('STEP: When I insert the route') From 7267b3a8215d8cbbba690ee1f7bcedc40cee3a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Abdelkader=20Mart=C3=ADnez=20P=C3=A9rez?= Date: Tue, 20 Aug 2019 09:59:23 +0200 Subject: [PATCH 4/7] make catalog to show step catalog --- spec/test/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/test/Makefile b/spec/test/Makefile index a73f203..49b8678 100644 --- a/spec/test/Makefile +++ b/spec/test/Makefile @@ -1,3 +1,5 @@ test: gherkin-lint - pipenv run behave --no-capture + pipenv run behave --no-capture --stop +catalog: + pipenv run behave --steps-catalog From 6368532717360c02319deb45774f2d78665d29d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Abdelkader=20Mart=C3=ADnez=20P=C3=A9rez?= Date: Tue, 20 Aug 2019 09:59:38 +0200 Subject: [PATCH 5/7] Parametrize step --- spec/test/features/steps/steps.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/test/features/steps/steps.py b/spec/test/features/steps/steps.py index bb73e67..145891c 100644 --- a/spec/test/features/steps/steps.py +++ b/spec/test/features/steps/steps.py @@ -106,13 +106,13 @@ def step_impl(context): raise NotImplementedError('STEP: Then I get an empty response body') -@when('I delete the route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"') -def step_impl(context): +@when('I delete the route with id "{id}"') +def step_impl(context, id): raise NotImplementedError('STEP: When I delete the route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"') -@given('It has a route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"') -def step_impl(context): +@given('It has a route with id "{id}"') +def step_impl(context, id): raise NotImplementedError('STEP: Given It has a route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"') @when('I insert the route') From 7c5f127f2219d2ef3835827071b23c5683748340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Abdelkader=20Mart=C3=ADnez=20P=C3=A9rez?= Date: Tue, 20 Aug 2019 10:29:30 +0200 Subject: [PATCH 6/7] If no interactive without scripts is not interactive. --- poc/bin/kapow | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/poc/bin/kapow b/poc/bin/kapow index cf01e47..0dd3b0c 100755 --- a/poc/bin/kapow +++ b/poc/bin/kapow @@ -313,7 +313,10 @@ async def run_init_script(app, scripts, interactive): """ if not scripts: # No script given - cmd = "/bin/bash" + if not interactive: + return + else: + cmd = "/bin/bash" else: def build_filenames(): for filename in scripts: @@ -402,8 +405,6 @@ def server(certfile, keyfile, bind, interactive, scripts): if bool(certfile) ^ bool(keyfile): print("For SSL both 'certfile' and 'keyfile' should be provided.") sys.exit(1) - if not scripts: - interactive = True loop.run_until_complete(start_kapow_server(bind, scripts, certfile, interactive, keyfile)) loop.run_forever() From 0a93135b4eb1d9a369cba7c147068b519784a645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Abdelkader=20Mart=C3=ADnez=20P=C3=A9rez?= Date: Tue, 20 Aug 2019 10:29:58 +0200 Subject: [PATCH 7/7] Check for reachable API in initial step. --- spec/test/features/steps/steps.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/spec/test/features/steps/steps.py b/spec/test/features/steps/steps.py index 145891c..c95a2d1 100644 --- a/spec/test/features/steps/steps.py +++ b/spec/test/features/steps/steps.py @@ -1,8 +1,11 @@ import subprocess from time import sleep +import shlex +import socket +from contextlib import suppress import requests -from environconfig import EnvironConfig, StringVar +from environconfig import EnvironConfig, StringVar, IntVar class Env(EnvironConfig): @@ -15,17 +18,31 @@ class Env(EnvironConfig): #: Where the Data API is KAPOW_DATAAPI_URL = StringVar(default="http://localhost:8080") + KAPOW_BOOT_TIMEOUT = IntVar(default=10) @given('I have a just started Kapow! server') @given('I have a running Kapow! server') def step_impl(context): context.server = subprocess.Popen( - Env.KAPOW_SERVER_CMD, + shlex.split(Env.KAPOW_SERVER_CMD), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, - shell=True) - is_running = context.server.poll() is None - assert is_running, "Server is not running!" + shell=False) + + # Check process is running with reachable APIs + open_ports = False + for _ in range(Env.KAPOW_BOOT_TIMEOUT): + is_running = context.server.poll() is None + assert is_running, "Server is not running!" + with suppress(requests.exceptions.ConnectionError): + open_ports = ( + requests.head(Env.KAPOW_CONTROLAPI_URL, timeout=1).status_code + and requests.head(Env.KAPOW_DATAAPI_URL, timeout=1).status_code) + if open_ports: + break + sleep(1) + + assert open_ports, "API is unreachable after KAPOW_BOOT_TIMEOUT" @when('I request a routes listing')