Skip to content

Commit 95b01d8

Browse files
committed
refactor(config): minimise and standardise between .sls & .tst
1 parent cce5e67 commit 95b01d8

File tree

2 files changed

+34
-50
lines changed

2 files changed

+34
-50
lines changed

cron/config/file.sls

+13-15
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@
55
{%- set tplroot = tpldir.split('/')[0] %}
66
{%- from tplroot ~ "/map.jinja" import cron with context %}
77
8-
{%- if 'tasks' in cron %}
9-
{%- for task, task_options in cron.tasks.items() %}
8+
{%- for task, task_options in cron.get('tasks', {}).items() %}
9+
{%- set cron_type = task_options.type|d('present') %}
1010
1111
cron.{{ task }}:
12-
cron.{{ task_options.type|d('present') }}:
12+
cron.{{ cron_type }}:
1313
- name: {{ task_options.name }}
14-
- identifier: '{{ task }}'
15-
{%- if 'user' in task_options %}
1614
- user: {{ task_options.user|d('root') }}
15+
- identifier: '{{ task }}'
16+
{%- if cron_type == 'present' %}
17+
- commented: {{ task_options.commented|d(False) }}
18+
{%- for section in ['minute', 'hour', 'daymonth', 'month', 'dayweek', 'comment', 'special'] %}
19+
{%- if section in task_options %}
20+
- {{ section }}: '{{ task_options[section] }}'
21+
{%- endif %}
22+
{%- endfor %}
1723
{%- endif %}
18-
{%- for section in ['minute', 'hour', 'daymonth', 'month', 'dayweek', 'comment', 'special'] %}
19-
{%- if section in task_options %}
20-
- {{ section }}: '{{ task_options.get(section) }}'
21-
{%- endif %}
22-
{%- endfor %}
23-
{%- if task_options.commented|d(False) %}
24-
- commented: True
25-
{%- endif %}
26-
{%- endfor %}
27-
{%- endif %}
24+
25+
{%- endfor %}

cron/saltcheck-tests/config.tst

+21-35
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,45 @@
33

44
{%- set cron = salt['pillar.get']('cron', {}) %}
55

6-
{%- if 'tasks' in cron %}
7-
{%- for task, task_options in cron.tasks.items() %}
6+
{%- for task, task_options in cron.get('tasks', {}).items() %}
7+
{%- set cron_type = task_options.type|d('present') %}
88

9-
{%- if task_options.type == 'absent' %}
10-
validate_cron.{{ task }}_absent:
9+
validate_cron.{{ task }}_{{ cron_type }}:
1110
module_and_function: cron.get_entry
1211
args:
1312
- {{ task_options.user|d('root') }}
1413
- {{ task }}
14+
{%- if cron_type == 'absent' %}
1515
assertion: assertFalse
16+
{%- else %}
17+
assertion: assertEqual
18+
assertion_section: identifier
19+
expected-return: {{ task }}
20+
{%- endif %}
1621

17-
{%- elif task_options.type == 'present' %}
18-
validate_cron.{{ task }}_exists:
22+
{%- if cron_type == 'present' %}
23+
validate_cron.{{ task }}_commented:
1924
module_and_function: cron.get_entry
2025
args:
2126
- {{ task_options.user|d('root') }}
2227
- {{ task }}
23-
assertion: assertEqual
24-
assertion_section: identifier
25-
expected-return: {{ task }}
28+
assertion: {{ 'assertTrue' if task_options.commented|d(False) else 'assertFalse' }}
29+
assertion_section: commented
2630

2731
{#- Note: `special` is `spec` in the module #}
28-
{%- for section in ['minute', 'hour', 'daymonth', 'month', 'dayweek', 'comment', 'spec'] %}
29-
{%- if section in task_options %}
30-
{%- set assertion = 'assertEqual' %}
31-
{%- set expected = task_options.get(section) %}
32-
{%- if expected == 'random' %}
33-
{%- set assertion = 'assertLessEqual' %}
34-
{%- set expected = 0 %}
35-
{%- endif %}
32+
{%- for section in ['minute', 'hour', 'daymonth', 'month', 'dayweek', 'comment', 'spec'] %}
33+
{%- if section in task_options %}
34+
{%- set expected = task_options[section] %}
3635
validate_cron.{{ task }}_{{ section }}:
3736
module_and_function: cron.get_entry
3837
args:
3938
- {{ task_options.user|d('root') }}
4039
- {{ task }}
41-
assertion: {{ assertion }}
40+
assertion: {{ 'assertLessEqual' if expected == 'random' else 'assertEqual' }}
4241
assertion_section: {{ section }}
43-
expected-return: '{{ expected }}'
44-
{%- endif %}
45-
{%- endfor %}
46-
47-
{%- set assertion = 'assertFalse' %}
48-
{%- if task_options.commented|d(False) %}
49-
{%- set assertion = 'assertTrue' %}
42+
expected-return: '{{ 0 if expected == 'random' else expected }}'
5043
{%- endif %}
51-
validate_cron.{{ task }}_commented:
52-
module_and_function: cron.get_entry
53-
args:
54-
- {{ task_options.user|d('root') }}
55-
- {{ task }}
56-
assertion: {{ assertion }}
57-
assertion_section: commented
58-
{%- endif %}
44+
{%- endfor %}
45+
{%- endif %}
5946
60-
{%- endfor %}
61-
{%- endif %}
47+
{%- endfor %}

0 commit comments

Comments
 (0)