| 1 |
#################################################################### |
| 2 |
# WARNING: These are designed specifically for Ansible tests # |
| 3 |
# and should not be used as examples of how to write Ansible roles # |
| 4 |
#################################################################### |
| 5 |
|
| 6 |
# Copyright (c) 2024, Max Maxopoly <[email protected]> |
| 7 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 8 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 9 |
- name: Run apk tests on Alpine |
| 10 |
when: ansible_facts.distribution in ['Alpine'] |
| 11 |
block: |
| 12 |
- name: Ensure vim is not installed |
| 13 |
community.general.apk: |
| 14 |
name: vim |
| 15 |
state: absent |
| 16 |
|
| 17 |
- name: Install vim |
| 18 |
community.general.apk: |
| 19 |
name: vim |
| 20 |
state: present |
| 21 |
register: results |
| 22 |
|
| 23 |
- name: Ensure vim was installed |
| 24 |
ansible.builtin.assert: |
| 25 |
that: |
| 26 |
- results is changed |
| 27 |
- (results.packages | length) >= 1 # vim has dependencies, so depending on the base image this number may vary |
| 28 |
|
| 29 |
- name: Install vim again |
| 30 |
community.general.apk: |
| 31 |
name: vim |
| 32 |
state: present |
| 33 |
register: results |
| 34 |
|
| 35 |
- name: Ensure vim was not installed again |
| 36 |
ansible.builtin.assert: |
| 37 |
that: |
| 38 |
- results is not changed |
| 39 |
- (results.packages | default([]) | length) == 0 |
| 40 |
|
| 41 |
- name: Ensure vim is not installed |
| 42 |
community.general.apk: |
| 43 |
name: vim |
| 44 |
state: absent |
| 45 |
register: results |
| 46 |
|
| 47 |
- name: Ensure vim was uninstalled |
| 48 |
ansible.builtin.assert: |
| 49 |
that: |
| 50 |
- results is changed |
| 51 |
- (results.packages | length) >= 1 |
| 52 |
|
| 53 |
- name: Install vim without cache |
| 54 |
community.general.apk: |
| 55 |
name: vim |
| 56 |
state: present |
| 57 |
no_cache: true |
| 58 |
register: results |
| 59 |
|
| 60 |
- name: Ensure vim was installed without cache |
| 61 |
ansible.builtin.assert: |
| 62 |
that: |
| 63 |
- results is changed |
| 64 |
|
| 65 |
- name: Install vim again without cache |
| 66 |
community.general.apk: |
| 67 |
name: vim |
| 68 |
state: present |
| 69 |
no_cache: true |
| 70 |
register: results |
| 71 |
|
| 72 |
- name: Ensure vim was not installed again without cache |
| 73 |
ansible.builtin.assert: |
| 74 |
that: |
| 75 |
- results is not changed |
| 76 |
- (results.packages | default([]) | length) == 0 |
| 77 |
|
| 78 |
- name: Ensure a bunch of packages aren't installed |
| 79 |
community.general.apk: |
| 80 |
name: |
| 81 |
- less |
| 82 |
- nano |
| 83 |
- vim |
| 84 |
state: absent |
| 85 |
|
| 86 |
- name: Install a bunch of packages |
| 87 |
community.general.apk: |
| 88 |
name: |
| 89 |
- less |
| 90 |
- nano |
| 91 |
- vim |
| 92 |
- bash |
| 93 |
- bash-completion |
| 94 |
- bash-completion-doc |
| 95 |
- zsh |
| 96 |
- zsh-calendar |
| 97 |
- zsh-completions |
| 98 |
- zsh-doc |
| 99 |
state: present |
| 100 |
register: results |
| 101 |
|
| 102 |
- name: Ensure a bunch of packages were installed |
| 103 |
ansible.builtin.assert: |
| 104 |
that: |
| 105 |
- results is changed |
| 106 |
- (results.packages | length) >= 10 |
| 107 |
|
| 108 |
- name: Install a bunch of packages again |
| 109 |
community.general.apk: |
| 110 |
name: |
| 111 |
- less |
| 112 |
- nano |
| 113 |
- vim |
| 114 |
state: present |
| 115 |
register: results |
| 116 |
|
| 117 |
- name: Ensure a bunch of packages were not installed again |
| 118 |
ansible.builtin.assert: |
| 119 |
that: |
| 120 |
- results is not changed |
| 121 |
- (results.packages | default([]) | length) == 0 |
| 122 |
|
| 123 |
- name: Ensure a bunch of packages are not installed |
| 124 |
community.general.apk: |
| 125 |
name: |
| 126 |
- less |
| 127 |
- nano |
| 128 |
- vim |
| 129 |
state: absent |
| 130 |
register: results |
| 131 |
|
| 132 |
- name: Ensure a bunch of packages were uninstalled |
| 133 |
ansible.builtin.assert: |
| 134 |
that: |
| 135 |
- results is changed |
| 136 |
- (results.packages | length) >= 3 |
| 137 |
|
| 138 |
- name: Install a bunch of packages without cache |
| 139 |
community.general.apk: |
| 140 |
name: |
| 141 |
- less |
| 142 |
- nano |
| 143 |
- vim |
| 144 |
state: present |
| 145 |
no_cache: true |
| 146 |
register: results |
| 147 |
|
| 148 |
- name: Ensure a bunch of packages were installed without cache |
| 149 |
ansible.builtin.assert: |
| 150 |
that: |
| 151 |
- results is changed |
| 152 |
|
| 153 |
- name: Install a bunch of packages again without cache |
| 154 |
community.general.apk: |
| 155 |
name: |
| 156 |
- less |
| 157 |
- nano |
| 158 |
- vim |
| 159 |
state: present |
| 160 |
no_cache: true |
| 161 |
register: results |
| 162 |
|
| 163 |
- name: Ensure a bunch of packages were not installed again without cache |
| 164 |
ansible.builtin.assert: |
| 165 |
that: |
| 166 |
- results is not changed |
| 167 |
- (results.packages | default([]) | length) == 0 |
| 168 |
|
| 169 |
- name: Install package with empty name |
| 170 |
community.general.apk: |
| 171 |
name: "" |
| 172 |
register: result_empty |
| 173 |
ignore_errors: true |
| 174 |
|
| 175 |
- name: Assert failure due to empty package name |
| 176 |
ansible.builtin.assert: |
| 177 |
that: |
| 178 |
- result_empty is failed |
| 179 |
- "'Package name(s) cannot be empty or whitespace-only' == result_empty.msg" |
| 180 |
|
| 181 |
- name: Install package name with only spaces |
| 182 |
community.general.apk: |
| 183 |
name: [" "] |
| 184 |
register: result_spaces |
| 185 |
ignore_errors: true |
| 186 |
|
| 187 |
- name: Assert failure due to whitespace-only package name |
| 188 |
ansible.builtin.assert: |
| 189 |
that: |
| 190 |
- result_spaces is failed |
| 191 |
- "'Package name(s) cannot be empty or whitespace-only' == result_spaces.msg" |
| 192 |
|
| 193 |
- name: Do not accept list with valid and empty string |
| 194 |
community.general.apk: |
| 195 |
name: ["busybox", ""] |
| 196 |
register: result_invalid_mixed |
| 197 |
ignore_errors: true |
| 198 |
|
| 199 |
- name: Assert failure with mixed package list |
| 200 |
ansible.builtin.assert: |
| 201 |
that: |
| 202 |
- result_invalid_mixed is failed |
| 203 |
- "'Package name(s) cannot be empty or whitespace-only' == result_invalid_mixed.msg" |
| 204 |
|
| 205 |
- name: Reject package name list with multiple empty/whitespace-only strings |
| 206 |
community.general.apk: |
| 207 |
name: ["", " "] |
| 208 |
register: result_multiple_empty |
| 209 |
ignore_errors: true |
| 210 |
|
| 211 |
- name: Assert failure due to all package names being empty or whitespace |
| 212 |
ansible.builtin.assert: |
| 213 |
that: |
| 214 |
- result_multiple_empty is failed |
| 215 |
- "'Package name(s) cannot be empty or whitespace-only' == result_multiple_empty.msg" |
| 216 |
|
| 217 |
- name: Reject empty package name with update_cache parameter |
| 218 |
community.general.apk: |
| 219 |
name: "" |
| 220 |
update_cache: true |
| 221 |
register: result_empty_package_with_update_cache |
| 222 |
ignore_errors: true |
| 223 |
|
| 224 |
- name: Assert failure due to all package names being empty or whitespace |
| 225 |
ansible.builtin.assert: |
| 226 |
that: |
| 227 |
- result_empty_package_with_update_cache is failed |
| 228 |
- "'Package name(s) cannot be empty or whitespace-only' == result_empty_package_with_update_cache.msg" |