From 6cffa0f84fc881fc2eb0d8e6f20f888e760d039f Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Thu, 22 Feb 2024 21:04:00 +0100 Subject: [PATCH] [PR #7992/ffa3d158 backport][stable-7] Implement integration tests for apk (#8007) Implement integration tests for apk (#7992) * Implement integration tests for apk * Add group for apk integration test * Adjust integration tests of apk as suggested in PR (cherry picked from commit ffa3d15881dc83b709bf123524e53280b286a12d) Co-authored-by: Maxopoly --- tests/integration/targets/apk/aliases | 13 ++ tests/integration/targets/apk/tasks/main.yml | 160 +++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 tests/integration/targets/apk/aliases create mode 100644 tests/integration/targets/apk/tasks/main.yml diff --git a/tests/integration/targets/apk/aliases b/tests/integration/targets/apk/aliases new file mode 100644 index 0000000000..6e8c01586a --- /dev/null +++ b/tests/integration/targets/apk/aliases @@ -0,0 +1,13 @@ +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +azp/posix/2 +needs/root +destructive +skip/aix +skip/osx +skip/macos +skip/freebsd +skip/rhel +skip/ubuntu \ No newline at end of file diff --git a/tests/integration/targets/apk/tasks/main.yml b/tests/integration/targets/apk/tasks/main.yml new file mode 100644 index 0000000000..0e1b0ae429 --- /dev/null +++ b/tests/integration/targets/apk/tasks/main.yml @@ -0,0 +1,160 @@ +#################################################################### +# WARNING: These are designed specifically for Ansible tests # +# and should not be used as examples of how to write Ansible roles # +#################################################################### + +# Copyright (c) 2024, Max Maxopoly +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later +- name: Run apk tests on Alpine + when: ansible_distribution in ['Alpine'] + block: + - name: Ensure vim is not installed + community.general.apk: + name: vim + state: absent + + - name: Install vim + community.general.apk: + name: vim + state: present + register: results + + - name: Ensure vim was installed + ansible.builtin.assert: + that: + - results is changed + - (results.packages | length) >= 1 # vim has dependencies, so depending on the base image this number may vary + + - name: Install vim again + community.general.apk: + name: vim + state: present + register: results + + - name: Ensure vim was not installed again + ansible.builtin.assert: + that: + - results is not changed + - (results.packages | default([]) | length) == 0 + + - name: Ensure vim is not installed + community.general.apk: + name: vim + state: absent + register: results + + - name: Ensure vim was uninstalled + ansible.builtin.assert: + that: + - results is changed + - (results.packages | length) >= 1 + + - name: Install vim without cache + community.general.apk: + name: vim + state: present + no_cache: true + register: results + + - name: Ensure vim was installed without cache + ansible.builtin.assert: + that: + - results is changed + + - name: Install vim again without cache + community.general.apk: + name: vim + state: present + no_cache: true + register: results + + - name: Ensure vim was not installed again without cache + ansible.builtin.assert: + that: + - results is not changed + - (results.packages | default([]) | length) == 0 + + - name: Ensure a bunch of packages aren't installed + community.general.apk: + name: + - less + - nano + - vim + state: absent + + - name: Install a bunch of packages + community.general.apk: + name: + - less + - nano + - vim + state: present + register: results + + - name: Ensure a bunch of packages were installed + ansible.builtin.assert: + that: + - results is changed + - (results.packages | length) >= 3 + + - name: Install a bunch of packages again + community.general.apk: + name: + - less + - nano + - vim + state: present + register: results + + - name: Ensure a bunch of packages were not installed again + ansible.builtin.assert: + that: + - results is not changed + - (results.packages | default([]) | length) == 0 + + - name: Ensure a bunch of packages are not installed + community.general.apk: + name: + - less + - nano + - vim + state: absent + register: results + + - name: Ensure a bunch of packages were uninstalled + ansible.builtin.assert: + that: + - results is changed + - (results.packages | length) >= 3 + + - name: Install a bunch of packages without cache + community.general.apk: + name: + - less + - nano + - vim + state: present + no_cache: true + register: results + + - name: Ensure a bunch of packages were installed without cache + ansible.builtin.assert: + that: + - results is changed + + - name: Install a bunch of packages again without cache + community.general.apk: + name: + - less + - nano + - vim + state: present + no_cache: true + register: results + + - name: Ensure a bunch of packages were not installed again without cache + ansible.builtin.assert: + that: + - results is not changed + - (results.packages | default([]) | length) == 0