1# repeatable tests for each key type
2# takes in the following variables
3#   test_win_regedit_key_type: the type of key
4#   test_win_regedit_key_expected_type: the expected key type
5#   test_win_regedit_key_data1: the data to create first
6#   test_win_regedit_key_data2: the data to change tp
7#   test_win_regedit_key_expected_value_null: the expected value for a null key
8#   test_win_regedit_key_expected_value1: the expected value for the data1
9#   test_win_regedit_key_expected_value2: the expected value for the data2
10---
11- name: create a null {{test_win_regedit_key_type}} check
12  win_regedit:
13    path: '{{test_win_regedit_local_key}}'
14    name: empty_{{test_win_regedit_key_type}}
15    type: '{{test_win_regedit_key_type}}'
16    state: present
17  register: null_check
18  check_mode: yes
19
20- name: get actual on null {{test_win_regedit_key_type}} check
21  win_reg_stat:
22    path: '{{test_win_regedit_local_key}}'
23    name: empty_{{test_win_regedit_key_type}}
24  register: null_actual_check
25
26- name: assert create a null {{test_win_regedit_key_type}} check
27  assert:
28    that:
29    - null_check is changed
30    - null_check.data_changed == False
31    - null_check.data_type_changed == False
32    - null_actual_check.exists == False
33
34- name: create a null {{test_win_regedit_key_type}}
35  win_regedit:
36    path: '{{test_win_regedit_local_key}}'
37    name: empty_{{test_win_regedit_key_type}}
38    type: '{{test_win_regedit_key_type}}'
39    state: present
40  register: null_create
41
42- name: get actual on null {{test_win_regedit_key_type}}
43  win_reg_stat:
44    path: '{{test_win_regedit_local_key}}'
45    name: empty_{{test_win_regedit_key_type}}
46  register: null_create_actual
47
48- name: assert create a null {{test_win_regedit_key_type}}
49  assert:
50    that:
51    - null_create is changed
52    - null_create.data_changed == False
53    - null_create.data_type_changed == False
54    - null_create_actual.exists == True
55    - null_create_actual.raw_value == test_win_regedit_key_expected_value_null
56    - null_create_actual.type == test_win_regedit_key_expected_type
57  when: test_win_regedit_key_type not in ['dword', 'qword']
58
59# dword and qword are different, need to convert the expected value null to an int
60- name: assert create a null {{test_win_regedit_key_type}} for dword and qword
61  assert:
62    that:
63    - null_create is changed
64    - null_create.data_changed == False
65    - null_create.data_type_changed == False
66    - null_create_actual.exists == True
67    - null_create_actual.raw_value == test_win_regedit_key_expected_value_null|int
68    - null_create_actual.type == test_win_regedit_key_expected_type
69  when: test_win_regedit_key_type in ['dword', 'qword']
70
71- name: create a null {{test_win_regedit_key_type}} again
72  win_regedit:
73    path: '{{test_win_regedit_local_key}}'
74    name: empty_{{test_win_regedit_key_type}}
75    type: '{{test_win_regedit_key_type}}'
76    state: present
77  register: null_create_again
78
79- name: assert create a null {{test_win_regedit_key_type}} again
80  assert:
81    that:
82    - null_create_again is not changed
83
84- name: create a {{test_win_regedit_key_type}} check
85  win_regedit:
86    path: '{{test_win_regedit_local_key}}'
87    name: data_{{test_win_regedit_key_type}}
88    data: '{{test_win_regedit_key_data1}}'
89    type: '{{test_win_regedit_key_type}}'
90    state: present
91  register: data_create_check
92  check_mode: yes
93
94- name: get actual on {{test_win_regedit_key_type}} check
95  win_reg_stat:
96    path: '{{test_win_regedit_local_key}}'
97    name: data_{{test_win_regedit_key_type}}
98  register: data_create_actual_check
99
100- name: assert create a {{test_win_regedit_key_type}} check
101  assert:
102    that:
103    - data_create_check is changed
104    - data_create_check.data_changed == False
105    - data_create_check.data_type_changed == False
106    - data_create_actual_check.exists == False
107
108- name: create a {{test_win_regedit_key_type}}
109  win_regedit:
110    path: '{{test_win_regedit_local_key}}'
111    name: data_{{test_win_regedit_key_type}}
112    data: '{{test_win_regedit_key_data1}}'
113    type: '{{test_win_regedit_key_type}}'
114    state: present
115  register: data_create
116
117- name: get actual on {{test_win_regedit_key_type}}
118  win_reg_stat:
119    path: '{{test_win_regedit_local_key}}'
120    name: data_{{test_win_regedit_key_type}}
121  register: data_create_actual
122
123- name: assert create a {{test_win_regedit_key_type}}
124  assert:
125    that:
126    - data_create is changed
127    - data_create.data_changed == False
128    - data_create.data_type_changed == False
129    - data_create_actual.exists == True
130    - data_create_actual.raw_value == test_win_regedit_key_expected_value1
131    - data_create_actual.type == test_win_regedit_key_expected_type
132  when: test_win_regedit_key_type not in ['dword', 'qword']
133
134- name: assert create a {{test_win_regedit_key_type}} for dword or qword
135  assert:
136    that:
137    - data_create is changed
138    - data_create.data_changed == False
139    - data_create.data_type_changed == False
140    - data_create_actual.exists == True
141    - data_create_actual.raw_value == test_win_regedit_key_expected_value1|int
142    - data_create_actual.type == test_win_regedit_key_expected_type
143  when: test_win_regedit_key_type in ['dword', 'qword']
144
145- name: create a {{test_win_regedit_key_type}} again
146  win_regedit:
147    path: '{{test_win_regedit_local_key}}'
148    name: data_{{test_win_regedit_key_type}}
149    data: '{{test_win_regedit_key_data1}}'
150    type: '{{test_win_regedit_key_type}}'
151    state: present
152  register: data_create_again
153
154- name: assert create a {{test_win_regedit_key_type}} again
155  assert:
156    that:
157    - data_create_again is not changed
158
159- name: change existing {{test_win_regedit_key_type}} data check
160  win_regedit:
161    path: '{{test_win_regedit_local_key}}'
162    name: data_{{test_win_regedit_key_type}}
163    data: '{{test_win_regedit_key_data2}}'
164    type: '{{test_win_regedit_key_type}}'
165    state: present
166  register: change_data_check
167  check_mode: yes
168
169- name: get actual of change existing {{test_win_regedit_key_type}} data check
170  win_reg_stat:
171    path: '{{test_win_regedit_local_key}}'
172    name: data_{{test_win_regedit_key_type}}
173  register: change_data_actual_check
174
175- name: assert change existing {{test_win_regedit_key_type}} data check
176  assert:
177    that:
178    - change_data_check is changed
179    - change_data_check.data_changed == True
180    - change_data_check.data_type_changed == False
181    - change_data_actual_check == data_create_actual
182
183- name: change existing {{test_win_regedit_key_type}} data
184  win_regedit:
185    path: '{{test_win_regedit_local_key}}'
186    name: data_{{test_win_regedit_key_type}}
187    data: '{{test_win_regedit_key_data2}}'
188    type: '{{test_win_regedit_key_type}}'
189    state: present
190  register: change_data
191
192- name: get actual of change existing {{test_win_regedit_key_type}} data
193  win_reg_stat:
194    path: '{{test_win_regedit_local_key}}'
195    name: data_{{test_win_regedit_key_type}}
196  register: change_data_actual
197
198- name: assert change existing {{test_win_regedit_key_type}} data
199  assert:
200    that:
201    - change_data is changed
202    - change_data.data_changed == True
203    - change_data.data_type_changed == False
204    - change_data_actual.raw_value == test_win_regedit_key_expected_value2
205  when: test_win_regedit_key_type not in ['dword', 'qword']
206
207- name: assert change existing {{test_win_regedit_key_type}} data for dword or qword
208  assert:
209    that:
210    - change_data is changed
211    - change_data.data_changed == True
212    - change_data.data_type_changed == False
213    - change_data_actual.raw_value == test_win_regedit_key_expected_value2|int
214  when: test_win_regedit_key_type in ['dword', 'qword']
215
216- name: change existing {{test_win_regedit_key_type}} data again
217  win_regedit:
218    path: '{{test_win_regedit_local_key}}'
219    name: data_{{test_win_regedit_key_type}}
220    data: '{{test_win_regedit_key_data2}}'
221    type: '{{test_win_regedit_key_type}}'
222    state: present
223  register: change_data_again
224
225- name: assert change existing {{test_win_regedit_key_type}} data again
226  assert:
227    that:
228    - change_data_again is not changed
229