test(cloudflared): add the default molecule scenario
Runs without Cloudflare and without a real cloudflared: a stub of the Cloudflare API on the controller's loopback answers the tunnel, zone and DNS record calls through cloudflared_api_base_url, a stub binary stands in for the daemon, and the releases come from file:// URLs. Covers the converge with an update through _binary_update and its idempotence, the rendered files and the running unit, the input asserts, the deleted-tunnel and DNS guards, a stale hash and a failed checksum, the mint entry point (as child processes outside CI) and the remove path. The cloudflare_dns calls cannot reach the stub and are not run. Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
e308683431
commit
9a626962a5
8 files changed
+831
No files matched your search
@@ -0,0 +1,38 @@
|
||||
---
|
||||
# One failing run: runs the main entry point with the inputs of the case and asserts that the
|
||||
# expected message, not something else, stopped it. Input: cloudflared_test_case (name, vars,
|
||||
# expect). Task vars cannot come from a template as a whole, so each input a case may change is
|
||||
# passed with its scenario value as the default.
|
||||
- name: "Run the role, case {{ cloudflared_test_case.name }}"
|
||||
block:
|
||||
- name: "Include the role, case {{ cloudflared_test_case.name }}"
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.cloudflared
|
||||
vars:
|
||||
cloudflared_version: "{{ cloudflared_test_case.vars.cloudflared_version | default('2026.2.0') }}"
|
||||
cloudflared_sha256_amd64: >-
|
||||
{{ cloudflared_test_case.vars.cloudflared_sha256_amd64
|
||||
| default(cloudflared_test_stub | replace('@VERSION@', '2026.2.0') | hash('sha256')) }}
|
||||
cloudflared_tunnel_id: "{{ cloudflared_test_case.vars.cloudflared_tunnel_id | default(cloudflared_test_tunnel_id) }}"
|
||||
cloudflared_credentials_json: "{{ cloudflared_test_case.vars.cloudflared_credentials_json | default(cloudflared_test_credentials_json) }}"
|
||||
cloudflared_account_id: "{{ cloudflared_test_case.vars.cloudflared_account_id | default('molecule-account') }}"
|
||||
cloudflared_manage_dns: "{{ cloudflared_test_case.vars.cloudflared_manage_dns | default(false) }}"
|
||||
cloudflared_zone_name: "{{ cloudflared_test_case.vars.cloudflared_zone_name | default('') }}"
|
||||
cloudflared_ingress: "{{ cloudflared_test_case.vars.cloudflared_ingress | default(cloudflared_test_ingress) }}"
|
||||
|
||||
# Only reached when the include returned. The message must not contain the expected
|
||||
# text, so the rescue below cannot mistake it for the failure under test.
|
||||
- name: "Fail because the include returned, case {{ cloudflared_test_case.name }}"
|
||||
ansible.builtin.fail:
|
||||
msg: The role accepted the input
|
||||
rescue:
|
||||
# A failed loop task reports its message per item.
|
||||
- name: "The expected failure stopped the run, case {{ cloudflared_test_case.name }}"
|
||||
vars:
|
||||
cloudflared_test_messages: >-
|
||||
{{ (ansible_failed_result.msg | default('')) ~ ' '
|
||||
~ (ansible_failed_result.results | default([]) | map(attribute='msg', default='') | join(' ')) }}
|
||||
ansible.builtin.assert:
|
||||
that: cloudflared_test_case.expect in cloudflared_test_messages
|
||||
fail_msg: "Expected '{{ cloudflared_test_case.expect }}', got: {{ cloudflared_test_messages }}"
|
||||
quiet: true
|
||||
Reference in new issue
Block a user