aboutsummaryrefslogtreecommitdiff
path: root/spec/acceptance/tests/resource/cron/should_write_new_users_crontab_after_puppet_creates_them_spec.rb
blob: 12506ad3500cb9b0e67bdb43ff98df0dbbf69b93 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'spec_helper_acceptance'

RSpec.context 'when Puppet creates a user in the middle of its run' do
  let(:known_username) { "pl#{rand(999_999).to_i}" }
  let(:new_username) { "pl#{rand(999_999).to_i}" }

  before(:each) do
    step 'Ensure that the known user exists on all of the agents' do
      compatible_agents.each do |agent|
        user_present(agent, known_username)
      end
    end

    step 'Ensure that the new user does not exist on all of the agents' do
      compatible_agents.each do |agent|
        user_absent(agent, new_username)
      end
    end
  end

  after(:each) do
    step 'Teardown -- Ensure that both users are deleted on all of the agents' do
      compatible_agents.each do |agent|
        run_cron_on(agent, :remove, known_username)
        user_absent(agent, known_username)

        run_cron_on(agent, :remove, new_username)
        user_absent(agent, new_username)
      end
    end
  end

  compatible_agents.each do |agent|
    it "should be able to write their crontab on #{agent}" do
      puppet_result = nil
      step "Create the new user, and the known + new user's crontab entries with Puppet" do
        # Placing Cron[first_entry] before creating the new user
        # triggers a prefetch of all the Cron resources on the
        # system. This lets us test that the prefetch step marks
        # the crontab of an unknown user as empty instead of marking
        # it as a failure.
        manifest = [
          cron_manifest('first_entry', command: 'ls', user: known_username),
          user_manifest(new_username, ensure: :present),
          cron_manifest('second_entry', command: 'ls', user: new_username),
        ].join("\n\n")
        puppet_result = apply_manifest_on(agent, manifest)
      end

      step 'Verify that Puppet successfully evaluates a Cron resource associated with the new user' do
        assert_match(%r{Cron.*second_entry}, puppet_result.stdout, 'Puppet fails to evaluate a Cron resource associated with a new user')
      end

      step "Verify that Puppet did create the new user's crontab file" do
        assert_matching_arrays(['* * * * * ls'], crontab_entries_of(agent, new_username), "Puppet did not create the new user's crontab file")
      end
    end
  end
end