File: should_destroy_spec.rb

package info (click to toggle)
puppet-agent 8.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 27,392 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (45 lines) | stat: -rw-r--r-- 1,258 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'Should destroy a scheduled task', node: host do
  before :each do
    pp = <<-MANIFEST
    scheduled_task {'#{taskname}':
      ensure      => present,
      command     => 'c:\\\\windows\\\\system32\\\\notepad.exe',
      arguments   => "foo bar baz",
      working_dir => 'c:\\\\windows',
      trigger     => {
        schedule   => daily,
        start_time => '12:00',
      },
      provider => 'taskscheduler_api2'
    }
    MANIFEST
    apply_manifest(pp, catch_failures: true)
  end

  context 'with taskname' do
    let(:taskname) { "pl#{rand(999_999).to_i}" }

    it 'destroys the task' do
      # Verify the task exists
      query_cmd = "schtasks.exe /query /v /fo list /tn #{taskname}"
      run_shell(query_cmd)

      pp = <<-MANIFEST
      scheduled_task {'#{taskname}':
        ensure      => absent,
        provider    => 'taskscheduler_api2'
      }
      MANIFEST

      apply_manifest(pp, catch_failures: true)

      query_cmd = "schtasks.exe /query /v /fo list /tn #{taskname}"
      query_out = run_shell(query_cmd, expect_failures: true)
      expect(query_out.to_s).to match(%r{ERROR: The system cannot find the (file|path) specified})
    end
  end
end