Add integration tests for flatpak module

PR #42169
This commit is contained in:
Alexander Bethke 2018-09-07 17:49:26 +02:00 committed by Sviatoslav Sydorenko
parent 2ac647def8
commit 19acd5d4f7
6 changed files with 414 additions and 0 deletions

View file

@ -0,0 +1,7 @@
unsupported
destructive
skip/freebsd
skip/osx
skip/rhel
needs/root
needs/privileged

View file

@ -0,0 +1,2 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,193 @@
# - Tests with absent flatpak --------------------------------------------------
# state=present on absent flatpak
- name: Test addition of absent flatpak (check mode)
flatpak:
name: org.gnome.Characters
remote: flathub
state: present
register: addition_result
check_mode: true
- name: Verify addition of absent flatpak test result (check mode)
assert:
that:
- "addition_result.changed == true"
msg: "Adding an absent flatpak shall mark module execution as changed"
- name: Test non-existent idempotency of addition of absent flatpak (check mode)
flatpak:
name: org.gnome.Characters
remote: flathub
state: present
register: double_addition_result
check_mode: true
- name: Verify non-existent idempotency of addition of absent flatpak test result (check mode)
assert:
that:
- "double_addition_result.changed == true"
msg: |
Adding an absent flatpak a second time shall still mark module execution
as changed in check mode
# state=absent on absent flatpak
- name: Test removal of absent flatpak check mode
flatpak:
name: org.gnome.Characters
state: absent
register: removal_result
check_mode: true
- name: Verify removal of absent flatpak test result (check mode)
assert:
that:
- "removal_result.changed == false"
msg: "Removing an absent flatpak shall mark module execution as not changed"
# state=present with url on absent flatpak
- name: Test addition of absent flatpak with url (check mode)
flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref
remote: flathub
state: present
register: url_addition_result
check_mode: true
- name: Verify addition of absent flatpak with url test result (check mode)
assert:
that:
- "url_addition_result.changed == true"
msg: "Adding an absent flatpak from URL shall mark module execution as changed"
- name: Test non-existent idempotency of addition of absent flatpak with url (check mode)
flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref
remote: flathub
state: present
register: double_url_addition_result
check_mode: true
- name: >
Verify non-existent idempotency of additionof absent flatpak with url test
result (check mode)
assert:
that:
- "double_url_addition_result.changed == true"
msg: |
Adding an absent flatpak from URL a second time shall still mark module execution
as changed in check mode
# state=absent with url on absent flatpak
- name: Test removal of absent flatpak with url not doing anything (check mode)
flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref
state: absent
register: url_removal_result
check_mode: true
- name: Verify removal of absent flatpak with url test result (check mode)
assert:
that:
- "url_removal_result.changed == false"
msg: "Removing an absent flatpak shall mark module execution as not changed"
# - Tests with present flatpak -------------------------------------------------
# state=present on present flatpak
- name: Test addition of present flatpak (check mode)
flatpak:
name: org.gnome.Calculator
remote: flathub
state: present
register: addition_present_result
check_mode: true
- name: Verify addition test result of present flatpak (check mode)
assert:
that:
- "addition_present_result.changed == false"
msg: "Adding an present flatpak shall mark module execution as not changed"
# state=absent on present flatpak
- name: Test removal of present flatpak (check mode)
flatpak:
name: org.gnome.Calculator
state: absent
register: removal_present_result
check_mode: true
- name: Verify removal of present flatpak test result (check mode)
assert:
that:
- "removal_present_result.changed == true"
msg: "Removing a present flatpak shall mark module execution as changed"
- name: Test non-existent idempotency of removal (check mode)
flatpak:
name: org.gnome.Calculator
state: absent
register: double_removal_present_result
check_mode: true
- name: Verify non-existent idempotency of removal (check mode)
assert:
that:
- "double_removal_present_result.changed == true"
msg: |
Removing a present flatpak a second time shall still mark module execution
as changed in check mode
# state=present with url on present flatpak
- name: Test addition with url of present flatpak (check mode)
flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Calculator.flatpakref
remote: flathub
state: present
register: url_addition_present_result
check_mode: true
- name: Verify addition with url of present flatpak test result (check mode)
assert:
that:
- "url_addition_present_result.changed == false"
msg: "Adding a present flatpak from URL shall mark module execution as not changed"
# state=absent with url on present flatpak
- name: Test removal with url of present flatpak (check mode)
flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Calculator.flatpakref
state: absent
register: url_removal_present_result
check_mode: true
- name: Verify removal with url of present flatpak test result (check mode)
assert:
that:
- "url_removal_present_result.changed == true"
msg: "Removing an absent flatpak shall mark module execution as not changed"
- name: Test non-existent idempotency of removal with url of present flatpak (check mode)
flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Calculator.flatpakref
remote: flathub
state: absent
register: double_url_removal_present_result
check_mode: true
- name: >
Verify non-existent idempotency of installation with url of present
flatpak test result (check mode)
assert:
that:
- "double_url_removal_present_result.changed == true"
msg: Removing an absent flatpak a second time shall still mark module execution as changed

View file

@ -0,0 +1,56 @@
# (c) 2018, Alexander Bethke <oolongbrothers@gmx.net>
# (c) 2018, Ansible Project
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- block:
- import_tasks: setup.yml
become: true
# executable override
- name: Test executable override
flatpak:
name: org.gnome.Characters
remote: flathub
state: present
executable: nothing-that-exists
ignore_errors: true
register: executable_override_result
- name: Verify executable override test result
assert:
that:
- "executable_override_result.failed == true"
- "executable_override_result.changed == false"
msg: "Specifying non-existing executable shall fail module execution"
- import_tasks: check_mode.yml
become: false
- import_tasks: test.yml
become: false
vars:
method: user
- import_tasks: test.yml
become: true
vars:
method: system
when: |
ansible_distribution in ('Fedora', 'Ubuntu')

View file

@ -0,0 +1,41 @@
- name: Install flatpak on Fedora
dnf:
name: flatpak
state: present
become: true
when: ansible_distribution == 'Fedora'
- block:
- name: Activate flatpak ppa on Ubuntu
apt_repository:
repo: "ppa:alexlarsson/flatpak"
state: present
mode: 0644
- name: Install flatpak package on Ubuntu
apt:
name: flatpak
state: present
become: true
when: ansible_distribution == 'Ubuntu'
- name: Enable flathub for user
flatpak_remote:
name: flathub
state: present
flatpakrepo_url: https://dl.flathub.org/repo/flathub.flatpakrepo
method: user
- name: Enable flathub for system
flatpak_remote:
name: flathub
state: present
flatpakrepo_url: https://dl.flathub.org/repo/flathub.flatpakrepo
method: system
- name: Add flatpak for testing check mode on present flatpak
flatpak:
name: org.gnome.Calculator
remote: flathub
state: present

View file

@ -0,0 +1,115 @@
# state=present
- name: Test addition - {{ method }}
flatpak:
name: org.gnome.Characters
remote: flathub
state: present
method: "{{ method }}"
register: addition_result
- name: Verify addition test result - {{ method }}
assert:
that:
- "addition_result.changed == true"
msg: "state=preset shall add flatpak when absent"
- name: Test idempotency of addition - {{ method }}
flatpak:
name: org.gnome.Characters
remote: flathub
state: present
method: "{{ method }}"
register: double_addition_result
- name: Verify idempotency of addition test result - {{ method }}
assert:
that:
- "double_addition_result.changed == false"
msg: "state=present shall not do anything when flatpak is already present"
# state=absent
- name: Test removal - {{ method }}
flatpak:
name: org.gnome.Characters
state: absent
method: "{{ method }}"
register: removal_result
- name: Verify removal test result - {{ method }}
assert:
that:
- "removal_result.changed == true"
msg: "state=absent shall remove flatpak when present"
- name: Test idempotency of removal - {{ method }}
flatpak:
name: org.gnome.Characters
state: absent
method: "{{ method }}"
register: double_removal_result
- name: Verify idempotency of removal test result - {{ method }}
assert:
that:
- "double_removal_result.changed == false"
msg: "state=absent shall not do anything when flatpak is not present"
# state=present with url as name
- name: Test addition with url - {{ method }}
flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref
remote: flathub
state: present
method: "{{ method }}"
register: url_addition_result
- name: Verify addition test result - {{ method }}
assert:
that:
- "url_addition_result.changed == true"
msg: "state=preset with url as name shall add flatpak when absent"
- name: Test idempotency of addition with url - {{ method }}
flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref
remote: flathub
state: present
method: "{{ method }}"
register: double_url_addition_result
- name: Verify idempotency of addition with url test result - {{ method }}
assert:
that:
- "double_url_addition_result.changed == false"
msg: "state=present with url as name shall not do anything when flatpak is already present"
# state=absent with url as name
- name: Test removal with url - {{ method }}
flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref
state: absent
method: "{{ method }}"
register: url_removal_result
- name: Verify removal test result - {{ method }}
assert:
that:
- "url_removal_result.changed == true"
msg: "state=absent with url as name shall remove flatpak when present"
- name: Test idempotency of removal with url - {{ method }}
flatpak:
name: https://flathub.org/repo/appstream/org.gnome.Characters.flatpakref
state: absent
method: "{{ method }}"
register: double_url_removal_result
- name: Verify idempotency of removal with url test result - {{ method }}
assert:
that:
- "double_url_removal_result.changed == false"
msg: "state=absent with url as name shall not do anything when flatpak is not present"