| 1 |
--- |
| 2 |
#################################################################### |
| 3 |
# WARNING: These are designed specifically for Ansible tests # |
| 4 |
# and should not be used as examples of how to write Ansible roles # |
| 5 |
#################################################################### |
| 6 |
|
| 7 |
# Copyright (c) Ansible Project |
| 8 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 9 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 10 |
|
| 11 |
- name: record the output directory |
| 12 |
set_fact: deploy_helper_test_root={{remote_tmp_dir}}/deploy_helper_test_root |
| 13 |
|
| 14 |
- name: State=query with default parameters |
| 15 |
deploy_helper: path={{ deploy_helper_test_root }} state=query |
| 16 |
- name: Assert State=query with default parameters |
| 17 |
assert: |
| 18 |
that: |
| 19 |
- "'project_path' in deploy_helper" |
| 20 |
- "deploy_helper.current_path == deploy_helper.project_path ~ '/current'" |
| 21 |
- "deploy_helper.releases_path == deploy_helper.project_path ~ '/releases'" |
| 22 |
- "deploy_helper.shared_path == deploy_helper.project_path ~ '/shared'" |
| 23 |
- "deploy_helper.unfinished_filename == 'DEPLOY_UNFINISHED'" |
| 24 |
- "'previous_release' in deploy_helper" |
| 25 |
- "'previous_release_path' in deploy_helper" |
| 26 |
- "'new_release' in deploy_helper" |
| 27 |
- "'new_release_path' in deploy_helper" |
| 28 |
- "deploy_helper.new_release_path == deploy_helper.releases_path ~ '/' ~ deploy_helper.new_release" |
| 29 |
|
| 30 |
- name: State=query with relative overridden paths |
| 31 |
deploy_helper: path={{ deploy_helper_test_root }} current_path=CURRENT_PATH releases_path=RELEASES_PATH shared_path=SHARED_PATH state=query |
| 32 |
- name: Assert State=query with relative overridden paths |
| 33 |
assert: |
| 34 |
that: |
| 35 |
- "deploy_helper.current_path == deploy_helper.project_path ~ '/CURRENT_PATH'" |
| 36 |
- "deploy_helper.releases_path == deploy_helper.project_path ~ '/RELEASES_PATH'" |
| 37 |
- "deploy_helper.shared_path == deploy_helper.project_path ~ '/SHARED_PATH'" |
| 38 |
- "deploy_helper.new_release_path == deploy_helper.releases_path ~ '/' ~ deploy_helper.new_release" |
| 39 |
|
| 40 |
- name: State=query with absolute overridden paths |
| 41 |
deploy_helper: path={{ deploy_helper_test_root }} current_path=/CURRENT_PATH releases_path=/RELEASES_PATH shared_path=/SHARED_PATH state=query |
| 42 |
- name: Assert State=query with absolute overridden paths |
| 43 |
assert: |
| 44 |
that: |
| 45 |
- "deploy_helper.current_path == '/CURRENT_PATH'" |
| 46 |
- "deploy_helper.releases_path == '/RELEASES_PATH'" |
| 47 |
- "deploy_helper.shared_path == '/SHARED_PATH'" |
| 48 |
- "deploy_helper.new_release_path == deploy_helper.releases_path ~ '/' ~ deploy_helper.new_release" |
| 49 |
|
| 50 |
- name: State=query with overridden unfinished_filename |
| 51 |
deploy_helper: path={{ deploy_helper_test_root }} unfinished_filename=UNFINISHED_DEPLOY state=query |
| 52 |
- name: Assert State=query with overridden unfinished_filename |
| 53 |
assert: |
| 54 |
that: |
| 55 |
- "'UNFINISHED_DEPLOY' == deploy_helper.unfinished_filename" |
| 56 |
|
| 57 |
# Remove the root folder just in case it exists |
| 58 |
- file: path={{ deploy_helper_test_root }} state=absent |
| 59 |
|
| 60 |
- name: State=present with default parameters |
| 61 |
deploy_helper: path={{ deploy_helper_test_root }} state=present |
| 62 |
- stat: path={{ deploy_helper.releases_path }} |
| 63 |
register: releases_path |
| 64 |
- stat: path={{ deploy_helper.shared_path }} |
| 65 |
register: shared_path |
| 66 |
- name: Assert State=present with default parameters |
| 67 |
assert: |
| 68 |
that: |
| 69 |
- "releases_path.stat.exists" |
| 70 |
- "shared_path.stat.exists" |
| 71 |
|
| 72 |
# Setup older releases for tests |
| 73 |
- file: path={{ deploy_helper.releases_path }}/{{ item }} state=directory |
| 74 |
with_items: ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh'] |
| 75 |
# Setup the new release |
| 76 |
- file: path={{ deploy_helper.new_release_path }} state=directory |
| 77 |
# Add a buildfile, just like in a real deploy |
| 78 |
- copy: content='' dest={{ deploy_helper.new_release_path }}/{{ deploy_helper.unfinished_filename }} |
| 79 |
# Add a buildfile, to an older deploy |
| 80 |
- copy: content='' dest={{ deploy_helper.releases_path }}/third/{{ deploy_helper.unfinished_filename }} |
| 81 |
|
| 82 |
- name: State=finalize with default parameters |
| 83 |
deploy_helper: path={{ deploy_helper_test_root }} release={{ deploy_helper.new_release }} state=finalize |
| 84 |
- stat: path={{ deploy_helper.current_path }} |
| 85 |
register: current_path |
| 86 |
- stat: path={{ deploy_helper.current_path }}/DEPLOY_UNFINISHED |
| 87 |
register: current_path_unfinished_filename |
| 88 |
- name: Assert State=finalize with default parameters |
| 89 |
assert: |
| 90 |
that: |
| 91 |
- "current_path.stat.islnk" |
| 92 |
- "deploy_helper.new_release_path in current_path.stat.lnk_source" |
| 93 |
- "not current_path_unfinished_filename.stat.exists" |
| 94 |
- stat: path={{ deploy_helper.releases_path }}/third |
| 95 |
register: third_release_path |
| 96 |
- shell: "ls {{ deploy_helper.releases_path }} | wc -l" |
| 97 |
register: releases_count |
| 98 |
- name: Assert State=finalize with default parameters (clean=true checks) |
| 99 |
assert: |
| 100 |
that: |
| 101 |
- "not third_release_path.stat.exists" |
| 102 |
- "releases_count.stdout|trim == '6'" |
| 103 |
- deploy_helper: path={{ deploy_helper_test_root }} release={{ deploy_helper.new_release }} state=query |
| 104 |
- name: Assert State=finalize with default parameters (previous_release checks) |
| 105 |
assert: |
| 106 |
that: |
| 107 |
- "deploy_helper.new_release == deploy_helper.previous_release" |
| 108 |
|
| 109 |
- name: State=absent with default parameters |
| 110 |
deploy_helper: path={{ deploy_helper_test_root }} state=absent |
| 111 |
- stat: path={{ deploy_helper_test_root }} |
| 112 |
register: project_path |
| 113 |
- name: Assert State=absent with default parameters |
| 114 |
assert: |
| 115 |
that: |
| 116 |
- "not project_path.stat.exists" |
| 117 |
|
| 118 |
- debug: msg="Clearing all release data and facts ---------" |
| 119 |
|
| 120 |
- name: State=present with shared_path set to False |
| 121 |
deploy_helper: path={{ deploy_helper_test_root }} state=present shared_path='' |
| 122 |
- stat: path={{ deploy_helper.releases_path }} |
| 123 |
register: releases_path |
| 124 |
- stat: path={{ deploy_helper.shared_path }} |
| 125 |
register: shared_path |
| 126 |
when: deploy_helper.shared_path is truthy |
| 127 |
- name: Assert State=present with shared_path set to False |
| 128 |
assert: |
| 129 |
that: |
| 130 |
- "releases_path.stat.exists" |
| 131 |
- "deploy_helper.shared_path is falsy or not shared_path.stat.exists" |
| 132 |
|
| 133 |
# Setup older releases for tests |
| 134 |
- file: path={{ deploy_helper.releases_path }}/{{ item }} state=directory |
| 135 |
with_items: ['first', 'second', 'third', 'fourth', 'fifth'] |
| 136 |
# Setup the new release |
| 137 |
- file: path={{ deploy_helper.new_release_path }} state=directory |
| 138 |
# Add a buildfile, just like in a real deploy |
| 139 |
- copy: content='' dest={{ deploy_helper.new_release_path }}/{{ deploy_helper.unfinished_filename }} |
| 140 |
# Add a buildfile, to an older deploy |
| 141 |
- copy: content='' dest={{ deploy_helper.releases_path }}/third/{{ deploy_helper.unfinished_filename }} |
| 142 |
|
| 143 |
- shell: "ls {{ deploy_helper_test_root }}/releases | wc -l" |
| 144 |
register: before_releases_count |
| 145 |
- name: State=clean with keep_releases=3 |
| 146 |
deploy_helper: path={{ deploy_helper_test_root }} release={{ deploy_helper.new_release }} state=clean keep_releases=3 |
| 147 |
- stat: path={{ deploy_helper.releases_path }}/third |
| 148 |
register: third_release_path |
| 149 |
- shell: "ls {{ deploy_helper.releases_path }} | wc -l" |
| 150 |
register: releases_count |
| 151 |
- name: Assert State=finalize with default parameters (clean=true checks) |
| 152 |
assert: |
| 153 |
that: |
| 154 |
- "not third_release_path.stat.exists" |
| 155 |
- "before_releases_count.stdout|trim == '6'" |
| 156 |
- "releases_count.stdout|trim == '3'" |
| 157 |
|
| 158 |
# Remove the root folder |
| 159 |
- file: path={{ deploy_helper_test_root }} state=absent |