From 783f91c2e0228ef9e057b810b4b60c4f669ebab4 Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Tue, 30 Jun 2020 09:30:04 +0200 Subject: Make commit ids overridable in the script mock --- tests/fake.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/fake.sh b/tests/fake.sh index bbb4380..0303b61 100755 --- a/tests/fake.sh +++ b/tests/fake.sh @@ -1,14 +1,17 @@ #!/usr/bin/env bash binary="${0/*\/}" -fakeCommit="aaa000aaa000aaa000aaa000aaa000aaa000aaa0" +localCommit="${PRETEND_LOCAL_COMMIT:-aaa000aaa000aaa000aaa000aaa000aaa000aaa0}" +remoteCommit="${PRETEND_REMOTE_COMMIT:-bbb000bbb000bbb000bbb000bbb000bbb000bbb0}" if [ "${binary}" = "clever" ] && [ "${1}" = "--version" ]; then echo "2.6.1" elif [ "${binary}" = "clever" ] && [ "${1}" = "activity" ]; then - echo "2020-02-02T20:20:02+02:00 OK DEPLOY ${fakeCommit} Git" + echo "2020-02-02T20:20:02+02:00 OK DEPLOY ${remoteCommit} Git" +elif [ "${binary}" = "clever" ] && [ "${1}" = "status" ]; then + echo "test-app: running (1*pico, Commit: ${remoteCommit})" elif [ "${binary}" = "git" ]; then - echo "${fakeCommit}" + echo "${localCommit}" else echo "${1}" >> "${binary}-commands" echo "${binary} called with arguments: ${*}" -- cgit v1.2.3 From 75a2a2fbcc31766e2debab1c8bd5cdce42f14fb7 Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Tue, 30 Jun 2020 09:33:18 +0200 Subject: add a test for `noop-if-up-to-date` It makes sure `clever deploy` is _not_ called if the application is up-to-date on clever cloud --- tests/test-all.yml | 1 + tests/test-noop-deploy.yml | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/test-noop-deploy.yml (limited to 'tests') diff --git a/tests/test-all.yml b/tests/test-all.yml index 64eb239..145b16d 100644 --- a/tests/test-all.yml +++ b/tests/test-all.yml @@ -2,5 +2,6 @@ - import_playbook: ./test-simple-app.yml - import_playbook: ./test-configure-app.yml - import_playbook: ./test-haskell-app.yml +- import_playbook: ./test-noop-deploy.yml - import_playbook: ./test-scalability.yml - import_playbook: ./test-restart-app.yml diff --git a/tests/test-noop-deploy.yml b/tests/test-noop-deploy.yml new file mode 100644 index 0000000..13eed20 --- /dev/null +++ b/tests/test-noop-deploy.yml @@ -0,0 +1,35 @@ +--- +- name: Do nothing if the app is up-to-date on clever + hosts: localhost + remote_user: root + pre_tasks: + - file: + state: absent + path: ../clever-commands + roles: + - role: clever + vars: + clever_token: 123abc + clever_secret: cba321 + clever_app: app_00000000-0000-0000-0000-000000000000 + environment: + PRETEND_REMOTE_COMMIT: aaa000aaa000aaa000aaa000aaa000aaa000aaa0 + post_tasks: + - name: Check stubbed commands + shell: "{{ item.cmd }}" + ignore_errors: true + with_list: + - cmd: "! grep deploy ../clever-commands" + display: "Expected 'clever deploy' command to NOT be called" + vars: + display: "{{ item.display }}" + 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 }}" -- cgit v1.2.3 From 545c41a6694ac5273dbfe1a0e119be04eaeef468 Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Tue, 30 Jun 2020 15:33:22 +0200 Subject: fix(test): log all commads to `$binary-commands` Previously, only the commands not directly handled by the stub were logged. We want to log all commands instead --- tests/fake.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/fake.sh b/tests/fake.sh index 0303b61..65ff819 100755 --- a/tests/fake.sh +++ b/tests/fake.sh @@ -13,6 +13,7 @@ elif [ "${binary}" = "clever" ] && [ "${1}" = "status" ]; then elif [ "${binary}" = "git" ]; then echo "${localCommit}" else - echo "${1}" >> "${binary}-commands" echo "${binary} called with arguments: ${*}" fi + +echo "${1}" >> "${binary}-commands" -- cgit v1.2.3 From db630aaa8b261503076eb7320ee3cee5a5582be8 Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Tue, 30 Jun 2020 15:46:41 +0200 Subject: fix(tests): use `! grep` instead of `grep -v` `grep -v` makes sure a file contains other lines than the one that matched. This is different from `! grep` which makes sure the file does not contain a line that matched. --- tests/test-configure-app.yml | 4 ++-- tests/test-restart-app.yml | 6 +++--- tests/test-scalability.yml | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/test-configure-app.yml b/tests/test-configure-app.yml index 15987fd..e9861a2 100644 --- a/tests/test-configure-app.yml +++ b/tests/test-configure-app.yml @@ -21,7 +21,7 @@ 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 }}" + shell: "{{ item.cmd }}" ignore_errors: true vars: display: "{{ item.display }}" @@ -34,7 +34,7 @@ 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" + - cmd: "! grep restart ../clever-commands" display: "Expected 'clever restart' command to NOT be called" register: tests_results - name: show results diff --git a/tests/test-restart-app.yml b/tests/test-restart-app.yml index 4c13a14..bc880a8 100644 --- a/tests/test-restart-app.yml +++ b/tests/test-restart-app.yml @@ -15,16 +15,16 @@ clever_restart_only: true post_tasks: - name: Check stubbed commands - command: "{{ item.cmd }}" + shell: "{{ 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" + - cmd: "! grep deploy ../clever-commands" display: "Expected 'clever deploy' command to NOT be called" - - cmd: "grep -v scale ../clever-commands" + - cmd: "! grep scale ../clever-commands" display: "Expected 'clever scale' command to NOT be called" register: tests_results - name: show results diff --git a/tests/test-scalability.yml b/tests/test-scalability.yml index 6bb90d2..258beaf 100644 --- a/tests/test-scalability.yml +++ b/tests/test-scalability.yml @@ -29,7 +29,7 @@ flavors: { min: "nano", max: "XS" } post_tasks: - name: Check stubbed commands - command: "{{ item.cmd }}" + shell: "{{ item.cmd }}" ignore_errors: true vars: display: "{{ item.display }}" @@ -38,7 +38,7 @@ 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" + - cmd: "! grep restart ../clever-commands" display: "Expected 'clever restart' command to NOT be called" register: tests_results - name: show results -- cgit v1.2.3