---
- name: Create user for testing
  ansible.builtin.user:
    name: seuser
- name: Attempt to add mapping without 'seuser'
  register: selogin_error
  ignore_errors: true
  community.general.selogin:
    login: seuser
- name: Verify failure
  ansible.builtin.assert:
    that:
      - selogin_error is failed
- name: Map login to SELinux user
  register: selogin_new_mapping
  check_mode: "{{ item }}"
  with_items:
    - true
    - false
    - true
    - false
  community.general.selogin:
    login: seuser
    seuser: staff_u
- name: New mapping- verify functionality and check_mode
  ansible.builtin.assert:
    that:
      - selogin_new_mapping.results[0] is changed
      - selogin_new_mapping.results[1] is changed
      - selogin_new_mapping.results[2] is not changed
      - selogin_new_mapping.results[3] is not changed
- name: Change SELinux user login mapping
  register: selogin_mod_mapping
  check_mode: "{{ item }}"
  with_items:
    - true
    - false
    - true
    - false
  community.general.selogin:
    login: seuser
    seuser: user_u
- name: Changed mapping- verify functionality and check_mode
  ansible.builtin.assert:
    that:
      - selogin_mod_mapping.results[0] is changed
      - selogin_mod_mapping.results[1] is changed
      - selogin_mod_mapping.results[2] is not changed
      - selogin_mod_mapping.results[3] is not changed
- name: Remove SELinux user mapping
  register: selogin_del_mapping
  check_mode: "{{ item }}"
  with_items:
    - true
    - false
    - true
    - false
  community.general.selogin:
    login: seuser
    state: absent
- name: Delete mapping- verify functionality and check_mode
  ansible.builtin.assert:
    that:
      - selogin_del_mapping.results[0] is changed
      - selogin_del_mapping.results[1] is changed
      - selogin_del_mapping.results[2] is not changed
      - selogin_del_mapping.results[3] is not changed
- name: Remove test user
  ansible.builtin.user:
    name: seuser
    state: absent
