-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpuppetdb_command_spec.rb
More file actions
54 lines (44 loc) · 1.63 KB
/
puppetdb_command_spec.rb
File metadata and controls
54 lines (44 loc) · 1.63 KB
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
# frozen_string_literal: true
require 'spec_helper'
require 'bolt/executor'
describe 'puppetdb_command' do
let(:executor) { Bolt::Executor.new }
let(:pdb_client) { mock('pdb_client') }
let(:tasks) { true }
let(:command) { 'replace_facts' }
let(:payload) { {} }
let(:version) { 5 }
let(:instance) { 'instance' }
around(:each) do |example|
Puppet[:tasks] = tasks
Puppet.override(bolt_executor: executor, bolt_pdb_client: pdb_client) do
example.run
end
end
it 'calls Bolt::PuppetDB::Client.send_command' do
pdb_client.expects(:send_command).with(command, version, payload, nil).returns('uuid')
is_expected.to run.with_params(command, version, payload)
end
it 'calls Bolt::PuppetDB::Client.send_command with a named instance' do
pdb_client.expects(:send_command).with(command, version, payload, instance).returns('uuid')
is_expected.to run.with_params(command, version, payload, instance)
end
it 'errors if client does not implement :send_command' do
is_expected.to run
.with_params(command, version, payload)
.and_raise_error(/PuppetDB client .* does not implement :send_command/)
end
it 'reports the call to analytics' do
pdb_client.expects(:send_command).returns('uuid')
executor.expects(:report_function_call).with('puppetdb_command')
is_expected.to run.with_params(command, version, payload)
end
context 'without tasks enabled' do
let(:tasks) { false }
it 'errors' do
is_expected.to run
.with_params(command, version, payload)
.and_raise_error(/Plan language function 'puppetdb_command' cannot be used/)
end
end
end