From a97d82be88407384f977f50270bf314b1f76d22f Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Wed, 30 Jun 2021 17:36:56 +0430 Subject: [PATCH] Add integration tests for snap (#2907) * Add integration tests for snap * Also test on fedora and remove snapd if it was not installed * disable test for now --- tests/integration/targets/snap/aliases | 6 ++ tests/integration/targets/snap/tasks/main.yml | 72 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tests/integration/targets/snap/aliases create mode 100644 tests/integration/targets/snap/tasks/main.yml diff --git a/tests/integration/targets/snap/aliases b/tests/integration/targets/snap/aliases new file mode 100644 index 0000000000..d7f5ce60c5 --- /dev/null +++ b/tests/integration/targets/snap/aliases @@ -0,0 +1,6 @@ +shippable/posix/group1 +skip/aix +skip/freebsd +skip/osx +skip/macos +disabled #FIXME 2609 diff --git a/tests/integration/targets/snap/tasks/main.yml b/tests/integration/targets/snap/tasks/main.yml new file mode 100644 index 0000000000..e015122ff2 --- /dev/null +++ b/tests/integration/targets/snap/tasks/main.yml @@ -0,0 +1,72 @@ +--- +#################################################################### +# WARNING: These are designed specifically for Ansible tests # +# and should not be used as examples of how to write Ansible roles # +#################################################################### + +- name: install snapd + apt: + name: snapd + state: present + register: snapd_install_ubuntu + when: ansible_distribution == 'Ubuntu' + +- name: install snapd + dnf: + name: snapd + state: present + register: snapd_install_fedora + when: ansible_distribution == 'Fedora' + +- block: + - name: install package + community.general.snap: + name: hello-world + state: present + register: install + + - name: install package again + community.general.snap: + name: hello-world + state: present + register: install_again + + - name: Assert package has been installed just once + assert: + that: + - install is changed + - install_again is not changed + + - name: check package has been installed correctly + command: hello-world + + - name: remove package + community.general.snap: + name: hello-world + state: absent + register: remove + + - name: remove package again + community.general.snap: + name: hello-world + state: absent + register: remove_again + + - name: Assert package has been removed just once + assert: + that: + - remove is changed + - remove_again is not changed + when: ansible_distribution in ['Ubuntu','Fedora'] + +- name: Remove snapd in case it was not installed + apt: + name: snapd + state: absent + when: snapd_install_ubuntu is changed and ansible_distribution == 'Ubuntu' + +- name: Remove snapd in case it was not installed + dnf: + name: snapd + state: absent + when: snapd_install_fedora is changed and ansible_distribution == 'Fedora'