| 1 |
--- |
| 2 |
# Copyright (c) 2024 Colin Nolan <[email protected]> |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
- name: Create temp directory |
| 7 |
tempfile: |
| 8 |
state: directory |
| 9 |
register: temp_directory |
| 10 |
|
| 11 |
- name: Test block |
| 12 |
vars: |
| 13 |
manifest_path: "{{ temp_directory.path }}/Cargo.toml" |
| 14 |
package_name: hello-world-directory-test |
| 15 |
block: |
| 16 |
- name: Initialize package |
| 17 |
ansible.builtin.command: |
| 18 |
cmd: "cargo init --name {{ package_name }}" |
| 19 |
args: |
| 20 |
chdir: "{{ temp_directory.path }}" |
| 21 |
|
| 22 |
- name: Set package version (1.0.0) |
| 23 |
ansible.builtin.lineinfile: |
| 24 |
path: "{{ manifest_path }}" |
| 25 |
regexp: '^version = ".*"$' |
| 26 |
line: 'version = "1.0.0"' |
| 27 |
|
| 28 |
- name: Ensure package is uninstalled |
| 29 |
community.general.cargo: |
| 30 |
name: "{{ package_name }}" |
| 31 |
state: absent |
| 32 |
directory: "{{ temp_directory.path }}" |
| 33 |
register: uninstall_absent |
| 34 |
|
| 35 |
- name: Install package |
| 36 |
community.general.cargo: |
| 37 |
name: "{{ package_name }}" |
| 38 |
directory: "{{ temp_directory.path }}" |
| 39 |
register: install_absent |
| 40 |
|
| 41 |
- name: Change package version (1.0.1) |
| 42 |
ansible.builtin.lineinfile: |
| 43 |
path: "{{ manifest_path }}" |
| 44 |
regexp: '^version = ".*"$' |
| 45 |
line: 'version = "1.0.1"' |
| 46 |
|
| 47 |
- name: Install package again (present) |
| 48 |
community.general.cargo: |
| 49 |
name: "{{ package_name }}" |
| 50 |
state: present |
| 51 |
directory: "{{ temp_directory.path }}" |
| 52 |
register: install_present_state |
| 53 |
|
| 54 |
- name: Install package again (latest) |
| 55 |
community.general.cargo: |
| 56 |
name: "{{ package_name }}" |
| 57 |
state: latest |
| 58 |
directory: "{{ temp_directory.path }}" |
| 59 |
register: install_latest_state |
| 60 |
|
| 61 |
- name: Change package version (2.0.0) |
| 62 |
ansible.builtin.lineinfile: |
| 63 |
path: "{{ manifest_path }}" |
| 64 |
regexp: '^version = ".*"$' |
| 65 |
line: 'version = "2.0.0"' |
| 66 |
|
| 67 |
- name: Install package with given version (matched) |
| 68 |
community.general.cargo: |
| 69 |
name: "{{ package_name }}" |
| 70 |
version: "2.0.0" |
| 71 |
directory: "{{ temp_directory.path }}" |
| 72 |
register: install_given_version_matched |
| 73 |
|
| 74 |
- name: Install package with given version (unmatched) |
| 75 |
community.general.cargo: |
| 76 |
name: "{{ package_name }}" |
| 77 |
version: "2.0.1" |
| 78 |
directory: "{{ temp_directory.path }}" |
| 79 |
register: install_given_version_unmatched |
| 80 |
ignore_errors: true |
| 81 |
|
| 82 |
- name: Uninstall package |
| 83 |
community.general.cargo: |
| 84 |
name: "{{ package_name }}" |
| 85 |
state: absent |
| 86 |
directory: "{{ temp_directory.path }}" |
| 87 |
register: uninstall_present |
| 88 |
|
| 89 |
- name: Install non-existant package |
| 90 |
community.general.cargo: |
| 91 |
name: "{{ package_name }}-non-existant" |
| 92 |
state: present |
| 93 |
directory: "{{ temp_directory.path }}" |
| 94 |
register: install_non_existant |
| 95 |
ignore_errors: true |
| 96 |
|
| 97 |
- name: Install non-existant source directory |
| 98 |
community.general.cargo: |
| 99 |
name: "{{ package_name }}" |
| 100 |
state: present |
| 101 |
directory: "{{ temp_directory.path }}/non-existant" |
| 102 |
register: install_non_existant_source |
| 103 |
ignore_errors: true |
| 104 |
|
| 105 |
always: |
| 106 |
- name: Remove temp directory |
| 107 |
file: |
| 108 |
path: "{{ temp_directory.path }}" |
| 109 |
state: absent |
| 110 |
|
| 111 |
- name: Check assertions |
| 112 |
assert: |
| 113 |
that: |
| 114 |
- uninstall_absent is not changed |
| 115 |
- install_absent is changed |
| 116 |
- install_present_state is not changed |
| 117 |
- install_latest_state is changed |
| 118 |
- install_given_version_matched is changed |
| 119 |
- install_given_version_unmatched is failed |
| 120 |
- uninstall_present is changed |
| 121 |
- install_non_existant is failed |
| 122 |
- install_non_existant_source is failed |