<commit_before>require 'erb'
require 'dsc_utils'
test_name 'MODULES-2230 - C68706 - Apply DSC Registry Resource that Removes Registry Value'

confine(:to, :platform => 'windows')

# Init
local_files_root_path = ENV['MANIFESTS'] || 'tests/manifests'

# ERB Manifest
dsc_type = 'registry'
dsc_props = {
  :dsc_ensure    => 'Present',
  :dsc_key       => 'HKEY_LOCAL_MACHINE\SOFTWARE\TestKey',
  :dsc_valuename => 'TestRemoveValue',
  :dsc_valuedata => 'Cats',
  :dsc_valuetype => 'String'
}

dsc_manifest_template_path = File.join(local_files_root_path, 'basic_dsc_resources', 'dsc_single_resource.pp.erb')
dsc_manifest = ERB.new(File.read(dsc_manifest_template_path), 0, '>').result(binding)

# Tests
agents.each do |agent|
  step 'Apply Manifest to Create Value'
  on(agent, puppet('apply'), :stdin => dsc_manifest, :acceptable_exit_codes => [0,2]) do |result|
    assert_no_match(/Error:/, result.stderr, 'Unexpected error was detected!')
  end

  # New manifest to remove value.
  dsc_props[:dsc_ensure] = 'Absent'
  dsc_remove_manifest = ERB.new(File.read(dsc_manifest_template_path), 0, '>').result(binding)

  step 'Apply Manifest to Remove Value'
  on(agent, puppet('apply'), :stdin => dsc_remove_manifest, :acceptable_exit_codes => [0,2]) do |result|
    assert_no_match(/Error:/, result.stderr, 'Unexpected error was detected!')
  end

  step 'Verify Results'
  expect_failure('Expected to fail because of MODULES-2267') do
    assert_dsc_resource(
      agent,
      dsc_type,
      :Ensure    => dsc_props[:dsc_ensure],
      :Key       => dsc_props[:dsc_key],
      :ValueName => dsc_props[:dsc_valuename],
      :ValueData => "@(\"#{dsc_props[:dsc_valuedata]}\")",
      :ValueType => dsc_props[:dsc_valuetype]
    )
  end
end
<commit_msg>(MODULES-2285) Update Registry "absent" Test<commit_after>require 'erb'
require 'dsc_utils'
test_name 'MODULES-2230 - C68706 - Apply DSC Registry Resource that Removes Registry Value'

confine(:to, :platform => 'windows')

# Init
local_files_root_path = ENV['MANIFESTS'] || 'tests/manifests'

# ERB Manifest
dsc_type = 'registry'
dsc_props = {
  :dsc_ensure    => 'Present',
  :dsc_key       => 'HKEY_LOCAL_MACHINE\SOFTWARE\TestKey',
  :dsc_valuename => 'TestRemoveValue',
  :dsc_valuedata => 'Cats',
  :dsc_valuetype => 'String'
}

dsc_manifest_template_path = File.join(local_files_root_path, 'basic_dsc_resources', 'dsc_single_resource.pp.erb')
dsc_manifest = ERB.new(File.read(dsc_manifest_template_path), 0, '>').result(binding)

# Tests
agents.each do |agent|
  step 'Apply Manifest to Create Value'
  on(agent, puppet('apply'), :stdin => dsc_manifest, :acceptable_exit_codes => [0,2]) do |result|
    assert_no_match(/Error:/, result.stderr, 'Unexpected error was detected!')
  end

  # New manifest to remove value.
  dsc_props[:dsc_ensure] = 'Absent'
  dsc_remove_manifest = ERB.new(File.read(dsc_manifest_template_path), 0, '>').result(binding)

  step 'Apply Manifest to Remove Value'
  on(agent, puppet('apply'), :stdin => dsc_remove_manifest, :acceptable_exit_codes => [0,2]) do |result|
    assert_no_match(/Error:/, result.stderr, 'Unexpected error was detected!')
  end

  step 'Verify Results'
  assert_dsc_resource(
    agent,
    dsc_type,
    :Ensure    => dsc_props[:dsc_ensure],
    :Key       => dsc_props[:dsc_key],
    :ValueName => dsc_props[:dsc_valuename],
    :ValueData => "@(\"#{dsc_props[:dsc_valuedata]}\")",
    :ValueType => dsc_props[:dsc_valuetype]
  )
end

{'fraction_non_alphanumeric': 0.14339622641509434, 'fraction_numerical': 0.011030478955007257, 'mean_word_length': 4.9311531841652325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3524466', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1265, 'n_words': 250}