1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/snap/tasks/main.yml

190 lines
5.7 KiB
YAML
Raw Normal View History

---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
- block:
- name: Make sure package is not installed (hello-world)
community.general.snap:
name: hello-world
state: absent
- name: Install package (hello-world) (check mode)
community.general.snap:
name: hello-world
state: present
register: install_check
check_mode: true
- name: Install package (hello-world)
community.general.snap:
name: hello-world
state: present
register: install
- name: Install package again (hello-world) (check mode)
community.general.snap:
name: hello-world
state: present
register: install_again_check
check_mode: true
- name: Install package again (hello-world)
community.general.snap:
name: hello-world
state: present
register: install_again
- name: Assert package has been installed just once (hello-world)
assert:
that:
- install is changed
- install_check is changed
- install_again is not changed
- install_again_check is not changed
- name: Check package has been installed correctly (hello-world)
command: hello-world
environment:
PATH: /var/lib/snapd/snap/bin/
- name: Remove package (hello-world) (check mode)
community.general.snap:
name: hello-world
state: absent
register: remove_check
check_mode: true
- name: Remove package (hello-world)
community.general.snap:
name: hello-world
state: absent
register: remove
- name: Remove package again (hello-world) (check mode)
community.general.snap:
name: hello-world
state: absent
register: remove_again_check
check_mode: true
- name: Remove package again (hello-world)
community.general.snap:
name: hello-world
state: absent
register: remove_again
- name: Assert package has been removed just once (hello-world)
assert:
that:
- remove is changed
- remove_check is changed
- remove_again is not changed
- remove_again_check is not changed
- name: Make sure package from classic snap is not installed (nvim)
community.general.snap:
name: nvim
state: absent
- name: Install package from classic snap (nvim)
community.general.snap:
name: nvim
state: present
classic: true
register: classic_install
# testing classic idempotency
- name: Install package from classic snap again (nvim)
community.general.snap:
name: nvim
state: present
classic: true
register: classic_install_again
- name: Assert package has been installed just once (nvim)
assert:
that:
- classic_install is changed
- classic_install_again is not changed
# this is just testing if a package which has been installed
# with true classic can be removed without setting classic to true
- name: Remove package from classic snap without setting classic to true (nvim)
community.general.snap:
name: nvim
state: absent
register: classic_remove_without_true_classic
- name: Remove package from classic snap with setting classic to true (nvim)
community.general.snap:
name: nvim
state: absent
classic: true
register: classic_remove_with_true_classic
- name: Assert package has been removed without setting classic to true (nvim)
assert:
that:
- classic_remove_without_true_classic is changed
- classic_remove_with_true_classic is not changed
- name: Make sure package is not installed (uhttpd)
community.general.snap:
name: uhttpd
state: absent
- name: Install package (uhttpd)
community.general.snap:
name: uhttpd
state: present
register: install
- name: Install package (uhttpd)
community.general.snap:
name: uhttpd
state: present
options:
- "listening-port=8080"
register: install_with_option
- name: Install package again with option (uhttpd)
community.general.snap:
name: uhttpd
state: present
options:
- "listening-port=8080"
register: install_with_option_again
- name: Install package again with different options (uhttpd)
community.general.snap:
name: uhttpd
state: present
options:
- "listening-port=8088"
- "document-root-dir=/tmp"
register: install_with_option_changed
- name: Remove package (uhttpd)
community.general.snap:
name: uhttpd
state: absent
register: remove
- name: Assert package has been installed with options just once and only changed options trigger a change (uhttpd)
assert:
that:
- install is changed
- install_with_option is changed
- "install_with_option.options_changed[0] == 'uhttpd:listening-port=8080'"
- install_with_option_again is not changed
- install_with_option_changed is changed
- "'uhttpd:listening-port=8088' in install_with_option_changed.options_changed"
- "'uhttpd:document-root-dir=/tmp' in install_with_option_changed.options_changed"
- "'uhttpd:listening-port=8080' not in install_with_option_changed.options_changed"
- remove is changed
when: has_snap