From 19acd5d4f741ad520c053b42bda74bb1be15d05b Mon Sep 17 00:00:00 2001 From: Alexander Bethke Date: Fri, 7 Sep 2018 17:49:26 +0200 Subject: [PATCH] Add integration tests for flatpak module PR #42169 --- test/integration/targets/flatpak/aliases | 7 + .../integration/targets/flatpak/meta/main.yml | 2 + .../targets/flatpak/tasks/check_mode.yml | 193 ++++++++++++++++++ .../targets/flatpak/tasks/main.yml | 56 +++++ .../targets/flatpak/tasks/setup.yml | 41 ++++ .../targets/flatpak/tasks/test.yml | 115 +++++++++++ 6 files changed, 414 insertions(+) create mode 100644 test/integration/targets/flatpak/aliases create mode 100644 test/integration/targets/flatpak/meta/main.yml create mode 100644 test/integration/targets/flatpak/tasks/check_mode.yml create mode 100644 test/integration/targets/flatpak/tasks/main.yml create mode 100644 test/integration/targets/flatpak/tasks/setup.yml create mode 100644 test/integration/targets/flatpak/tasks/test.yml diff --git a/test/integration/targets/flatpak/aliases b/test/integration/targets/flatpak/aliases new file mode 100644 index 0000000000..094c5aa7ac --- /dev/null +++ b/test/integration/targets/flatpak/aliases @@ -0,0 +1,7 @@ +unsupported +destructive +skip/freebsd +skip/osx +skip/rhel +needs/root +needs/privileged diff --git a/test/integration/targets/flatpak/meta/main.yml b/test/integration/targets/flatpak/meta/main.yml new file mode 100644 index 0000000000..07faa21776 --- /dev/null +++ b/test/integration/targets/flatpak/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_tests diff --git a/test/integration/targets/flatpak/tasks/check_mode.yml b/test/integration/targets/flatpak/tasks/check_mode.yml new file mode 100644 index 0000000000..065f10dfa7 --- /dev/null +++ b/test/integration/targets/flatpak/tasks/check_mode.yml @@ -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 diff --git a/test/integration/targets/flatpak/tasks/main.yml b/test/integration/targets/flatpak/tasks/main.yml new file mode 100644 index 0000000000..daa7d8cd17 --- /dev/null +++ b/test/integration/targets/flatpak/tasks/main.yml @@ -0,0 +1,56 @@ +# (c) 2018, Alexander Bethke +# (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 . + +- 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') diff --git a/test/integration/targets/flatpak/tasks/setup.yml b/test/integration/targets/flatpak/tasks/setup.yml new file mode 100644 index 0000000000..954d56a0ce --- /dev/null +++ b/test/integration/targets/flatpak/tasks/setup.yml @@ -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 diff --git a/test/integration/targets/flatpak/tasks/test.yml b/test/integration/targets/flatpak/tasks/test.yml new file mode 100644 index 0000000000..5677dda289 --- /dev/null +++ b/test/integration/targets/flatpak/tasks/test.yml @@ -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"