---
- name: install NSSM
  chocolatey.chocolatey.win_chocolatey:
    name: NSSM
    state: present

- name: ensure testing folder exists
  ansible.windows.win_file:
    path: '{{test_win_nssm_path}}'
    state: directory

- name: create test user for service execution
  ansible.windows.win_user:
    name: '{{test_win_nssm_username}}'
    password: '{{test_win_nssm_password}}'
    state: present
    groups:
    - Users

# Run actual tests
- block:
  - include_tasks: tests.yml

  always:
    - name: ensure test service is absent
      ansible.windows.win_service:
        name: '{{ test_service_name }}'
        state: absent

    - name: remove test user
      ansible.windows.win_user:
        name: '{{test_win_nssm_username}}'
        state: absent

    - name: uninstall NSSM
      chocolatey.chocolatey.win_chocolatey:
        name: NSSM
        state: absent
      failed_when: false
