-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathget_target_spec.rb
More file actions
52 lines (41 loc) · 1.47 KB
/
get_target_spec.rb
File metadata and controls
52 lines (41 loc) · 1.47 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
# frozen_string_literal: true
require 'spec_helper'
require 'bolt/executor'
require 'bolt/inventory'
describe 'get_target' do
let(:executor) { Bolt::Executor.new }
let(:inventory) { Bolt::Inventory.empty }
let(:tasks_enabled) { true }
around(:each) do |example|
Puppet[:tasks] = tasks_enabled
Puppet.override(bolt_executor: executor, bolt_inventory: inventory) do
example.run
end
end
context 'with inventory' do
let(:hostname) { 'foo.example.com ' }
let(:target) { inventory.get_target(hostname) }
let(:groupname) { 'all' }
it 'with given uri' do
is_expected.to run.with_params(hostname).and_return(target)
end
it 'with given Target' do
is_expected.to run.with_params(target).and_return(target)
end
it 'with given Target in array' do
is_expected.to run.with_params([target]).and_return(target)
end
it 'errors when anything but a single target is returned' do
inventory.expects(:get_target).with(groupname).once.returns([anything, anything])
is_expected.to run.with_params(groupname)
.and_raise_error(Puppet::Pops::Types::TypeAssertionError)
end
it 'errors on unknown types' do
is_expected.to run.with_params(mock('anything')).and_raise_error(ArgumentError)
end
it 'reports the call to analytics' do
executor.expects(:report_function_call).with('get_target')
is_expected.to run.with_params(hostname).and_return(target)
end
end
end