r""" Test whether a DSC resource is in the desired state by calling ``Invoke-DscResource -Method Test``. Args: name (str): The name of the DSC resource to test. Required. module_name (str): The name of the PowerShell module that contains the res
(name, module_name, properties)
| 186 | |
| 187 | |
| 188 | def test(name, module_name, properties): |
| 189 | r""" |
| 190 | Test whether a DSC resource is in the desired state by calling |
| 191 | ``Invoke-DscResource -Method Test``. |
| 192 | |
| 193 | Args: |
| 194 | |
| 195 | name (str): |
| 196 | The name of the DSC resource to test. Required. |
| 197 | |
| 198 | module_name (str): |
| 199 | The name of the PowerShell module that contains the resource. |
| 200 | Required. |
| 201 | |
| 202 | properties (dict): |
| 203 | A dictionary of the desired resource properties. Required. |
| 204 | |
| 205 | Returns: |
| 206 | bool: ``True`` if the resource is already in the desired state, |
| 207 | ``False`` if changes are needed. |
| 208 | |
| 209 | Raises: |
| 210 | CommandExecutionError: If the PowerShell call fails. |
| 211 | SaltInvocationError: If required arguments are missing or invalid. |
| 212 | |
| 213 | CLI Example: |
| 214 | |
| 215 | .. code-block:: bash |
| 216 | |
| 217 | salt '*' dsc_resource.test File PSDesiredStateConfiguration \ |
| 218 | properties="{'DestinationPath': 'C:\\Temp\\test.txt', 'Ensure': 'Present'}" |
| 219 | |
| 220 | .. code-block:: bash |
| 221 | |
| 222 | salt '*' dsc_resource.test WindowsFeature PSDesiredStateConfiguration \ |
| 223 | properties="{'Name': 'Web-Server', 'Ensure': 'Present'}" |
| 224 | |
| 225 | .. versionadded:: 3008.1 |
| 226 | """ |
| 227 | if not name: |
| 228 | raise SaltInvocationError("name is required") |
| 229 | if not module_name: |
| 230 | raise SaltInvocationError("module_name is required") |
| 231 | if not isinstance(properties, dict): |
| 232 | raise SaltInvocationError("properties must be a dict") |
| 233 | |
| 234 | ps_prop = _dict_to_ps_hashtable(properties) |
| 235 | cmd = ( |
| 236 | f"(Invoke-DscResource" |
| 237 | f" -Name '{_ps_quote(name)}'" |
| 238 | f" -ModuleName '{_ps_quote(module_name)}'" |
| 239 | f" -Method Test" |
| 240 | f" -Property {ps_prop}).InDesiredState" |
| 241 | ) |
| 242 | log.debug("DSC Resource test: %s", cmd) |
| 243 | with PowerShellSession() as session: |
| 244 | result = session.run(cmd) |
| 245 | if isinstance(result, bool): |
nothing calls this directly
no test coverage detected