From 4525f9489fe792b0d7ee4ca76dc0c3706784d256 Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Mon, 22 Jun 2020 22:32:55 +0200 Subject: tests: expectations on binary stub --- tests/fake.sh | 1 + tests/test-configure-app.yml | 30 ++++++++++++++++++++++++++++++ tests/test-restart-app.yml | 27 +++++++++++++++++++++++++++ tests/test-scalability.yml | 27 +++++++++++++++++++++++++++ 4 files changed, 85 insertions(+) diff --git a/tests/fake.sh b/tests/fake.sh index 75bc051..bbb4380 100755 --- a/tests/fake.sh +++ b/tests/fake.sh @@ -10,5 +10,6 @@ elif [ "${binary}" = "clever" ] && [ "${1}" = "activity" ]; then elif [ "${binary}" = "git" ]; then echo "${fakeCommit}" else + echo "${1}" >> "${binary}-commands" echo "${binary} called with arguments: ${*}" fi diff --git a/tests/test-configure-app.yml b/tests/test-configure-app.yml index 06e5e92..15987fd 100644 --- a/tests/test-configure-app.yml +++ b/tests/test-configure-app.yml @@ -2,6 +2,10 @@ - name: Deploy an app & configure system details on clever hosts: localhost remote_user: root + pre_tasks: + - file: + state: absent + path: ../clever-commands roles: - role: clever vars: @@ -16,3 +20,29 @@ fail: msg: "CC_RUN_COMMAND env variable should not be present in the environment dict" when: clever_env.CC_RUN_COMMAND is defined + - name: Check stubbed commands + command: "{{ item.cmd }}" + ignore_errors: true + vars: + display: "{{ item.display }}" + with_list: + - cmd: "grep deploy ../clever-commands" + display: "Expected 'clever deploy' command to be called" + - cmd: "grep scale ../clever-commands" + display: "Expected 'clever scale' command to be called" + - cmd: "grep domain ../clever-commands" + display: "Expected 'clever domain' command to be called" + - cmd: "grep drain ../clever-commands" + display: "Expected 'clever drain' command to be called" + - cmd: "grep -v restart ../clever-commands" + display: "Expected 'clever restart' command to NOT be called" + register: tests_results + - name: show results + debug: + msg: + - "failed_results: {{ failed_results }}" + - "success_results: {{ success_results }}" + failed_when: tests_results is failed + vars: + failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}" + success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}" diff --git a/tests/test-restart-app.yml b/tests/test-restart-app.yml index 09d9936..4c13a14 100644 --- a/tests/test-restart-app.yml +++ b/tests/test-restart-app.yml @@ -2,6 +2,10 @@ - name: Restart app on clever hosts: localhost remote_user: root + pre_tasks: + - file: + state: absent + path: ../clever-commands roles: - role: clever vars: @@ -9,3 +13,26 @@ clever_secret: cba321 clever_app: app_00000000-0000-0000-0000-000000000000 clever_restart_only: true + post_tasks: + - name: Check stubbed commands + command: "{{ item.cmd }}" + ignore_errors: true + vars: + display: "{{ item.display }}" + with_list: + - cmd: "grep restart ../clever-commands" + display: "Expected 'clever restart' command to be called" + - cmd: "grep -v deploy ../clever-commands" + display: "Expected 'clever deploy' command to NOT be called" + - cmd: "grep -v scale ../clever-commands" + display: "Expected 'clever scale' command to NOT be called" + register: tests_results + - name: show results + debug: + msg: + - "failed_results: {{ failed_results }}" + - "success_results: {{ success_results }}" + failed_when: tests_results is failed + vars: + failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}" + success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}" diff --git a/tests/test-scalability.yml b/tests/test-scalability.yml index fefc86c..6bb90d2 100644 --- a/tests/test-scalability.yml +++ b/tests/test-scalability.yml @@ -15,6 +15,10 @@ - name: Configure scalability (no instances and ranged flavors) hosts: localhost remote_user: root + pre_tasks: + - file: + state: absent + path: ../clever-commands roles: - role: clever vars: @@ -23,6 +27,29 @@ clever_app: app_00000000-0000-0000-0000-000000000000 clever_scaling: flavors: { min: "nano", max: "XS" } + post_tasks: + - name: Check stubbed commands + command: "{{ item.cmd }}" + ignore_errors: true + vars: + display: "{{ item.display }}" + with_list: + - cmd: "grep deploy ../clever-commands" + display: "Expected 'clever deploy' command to be called" + - cmd: "grep scale ../clever-commands" + display: "Expected 'clever scale' command to be called" + - cmd: "grep -v restart ../clever-commands" + display: "Expected 'clever restart' command to NOT be called" + register: tests_results + - name: show results + debug: + msg: + - "failed_results: {{ failed_results }}" + - "success_results: {{ success_results }}" + failed_when: tests_results is failed + vars: + failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}" + success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}" - name: Configure scalability (incomplete flavors) hosts: localhost -- cgit v1.2.3