---
- hosts: localhost
  gather_facts: no
  tasks:
    - name: test ansible.legacy short group name
      module_defaults:
        group/testgroup:
          data: test
      block:
        - legacy_ping:
          register: result
        - assert:
            that: "result.ping == 'pong'"

        - ansible.legacy.legacy_ping:
          register: result
        - assert:
            that: "result.ping == 'pong'"

        - ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

        - ansible.legacy.ping:  # resolves to ansible.builtin.ping
          register: result
        - assert:
            that: "result.ping == 'test'"

        - ansible.builtin.ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

        - formerly_core_ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

        - ansible.builtin.formerly_core_ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

    - name: test group that includes a legacy action
      module_defaults:
        # As of 2.12, legacy actions must be included in the action group definition
        group/testlegacy:
          data: test
      block:
        - legacy_ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

        - ansible.legacy.legacy_ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

    - name: test ansible.builtin fully qualified group name
      module_defaults:
        group/ansible.builtin.testgroup:
          data: test
      block:
        # ansible.builtin does not contain ansible.legacy
        - legacy_ping:
          register: result
        - assert:
            that: "result.ping != 'test'"

        # ansible.builtin does not contain ansible.legacy
        - ansible.legacy.legacy_ping:
          register: result
        - assert:
            that: "result.ping != 'test'"

        - ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

        # Resolves to ansible.builtin.ping
        - ansible.legacy.ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

        - ansible.builtin.ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

        - formerly_core_ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

        - ansible.builtin.formerly_core_ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

    - name: test collection group name
      module_defaults:
        group/testns.testcoll.testgroup:
          data: test
      block:
        # Plugin resolving to a different collection does not get the default
        - ping:
          register: result
        - assert:
            that: "result.ping != 'test'"

        - formerly_core_ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

        - ansible.builtin.formerly_core_ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

        - testns.testcoll.ping:
          register: result
        - assert:
            that: "result.ping == 'test'"

        - metadata:
          collections:
            - testns.testcoll
