summaryrefslogtreecommitdiff
path: root/spec/support/shared/examples/client.rb
blob: 3c13cd767ef7d0a6a544be7c978ce81c52cf3fd8 (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

require "spec_helper"
require "spec/support/shared/context/client"

# requires platform and platform_version be defined
shared_examples "a completed run" do
  include_context "run completed"

  it "runs ohai, sets up authentication, loads node state, synchronizes policy, converges, and runs audits" do
    # This is what we're testing.
    expect(client.run).to be true

    # fork is stubbed, so we can see the outcome of the run
    expect(node.automatic_attrs[:platform]).to eq(platform)
    expect(node.automatic_attrs[:platform_version]).to eq(platform_version)
  end
end

shared_examples "a completed run with audit failure" do
  include_context "run completed"

  before do
    expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(Chef::Exceptions::RunFailedWrappingError)
  end

  it "converges, runs audits, saves the node and raises the error in a wrapping error" do
    expect { client.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error|
      expect(error.wrapped_errors.size).to eq(run_errors.size)
      run_errors.each do |run_error|
        expect(error.wrapped_errors).to include(run_error)
        expect(error.backtrace).to include(*run_error.backtrace)
      end
    end

    # fork is stubbed, so we can see the outcome of the run
    expect(node.automatic_attrs[:platform]).to eq(platform)
    expect(node.automatic_attrs[:platform_version]).to eq(platform_version)
  end
end

shared_examples "a failed run" do
  include_context "run failed"

  it "skips node save and raises the error in a wrapping error" do
    expect { client.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error|
      expect(error.wrapped_errors.size).to eq(run_errors.size)
      run_errors.each do |run_error|
        expect(error.wrapped_errors).to include(run_error)
        expect(error.backtrace).to include(*run_error.backtrace)
      end
    end
  end
end