Skip to content

Commit df05967

Browse files
committed
Fix molecule tests
1 parent 49a6308 commit df05967

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

molecule/no_default_labels/converge.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
hosts: all
44
become: yes
55
vars:
6+
runner_user: ansible
7+
github_repo: "{{ lookup('env', 'GITHUB_REPO') }}"
8+
github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}"
9+
runner_version: "latest"
10+
runner_name: test_name
611
runner_no_default_labels: true
712
runner_labels:
8-
- testlabel
9-
github_account: testuser
10-
github_repo: testrepo
13+
- testlabel1
14+
- testlabel2
1115
roles:
1216
- role: monolithprojects.github_actions_runner
17+

molecule/no_default_labels/molecule.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ platforms:
2424
verifier:
2525
name: ansible
2626
scenario:
27-
name: default
27+
name: no_default_labels
2828
test_sequence:
2929
- dependency
3030
- destroy
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
---
2-
# No extra requirements for this scenario
2+
3+
roles:
4+
- name: robertdebock.epel
5+
version: 3.0.1
Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
11
---
2-
- name: Verify runner_no_default_labels
2+
- name: Validate Repo runners
3+
user: ansible
34
hosts: all
4-
gather_facts: false
5+
gather_facts: yes
6+
become: yes
7+
vars:
8+
runner_user: ansible
9+
github_repo: "{{ lookup('env', 'GITHUB_REPO') }}"
10+
github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}"
11+
github_api_url: "https://api.github.com"
12+
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
13+
runner_name: "{{ ansible_facts.hostname }}"
14+
515
tasks:
6-
- name: Assert runner_no_default_labels is true
16+
- name: Check currently registered runners
17+
ansible.builtin.uri:
18+
url: "{{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners"
19+
headers:
20+
Authorization: "token {{ access_token }}"
21+
Accept: "application/vnd.github.v3+json"
22+
method: GET
23+
status_code: 200
24+
force_basic_auth: yes
25+
register: registered_runners
26+
27+
- name: Check Runner
728
ansible.builtin.assert:
829
that:
9-
- hostvars[inventory_hostname]['runner_no_default_labels'] | bool
10-
- name: Assert runner_labels contains testlabel
30+
- registered_runners.json.runners.0.status == "online"
31+
quiet: true
32+
33+
- debug:
34+
var: registered_runners.json.runners.0
35+
36+
- name: Set fact - current labels
37+
ansible.builtin.set_fact:
38+
current_labels: "{{ registered_runners.json.runners.0 | json_query('labels[*].name') | list }}"
39+
40+
- name: Check Labels (skipped if labels are OK)
1141
ansible.builtin.assert:
1242
that:
13-
- 'testlabel' in hostvars[inventory_hostname]['runner_labels']
43+
- current_labels == ['testlabel1', 'testlabel2']
44+
fail_msg: "Expected only the custom labels 'testlabel1' and 'testlabel2', but got {{ current_labels }}"

0 commit comments

Comments
 (0)