-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathremove_from_group_spec.rb
More file actions
90 lines (77 loc) · 3.1 KB
/
remove_from_group_spec.rb
File metadata and controls
90 lines (77 loc) · 3.1 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# frozen_string_literal: true
describe 'remove_from_group' do
let(:executor) { Bolt::Executor.new }
let(:config) { Bolt::Config.default }
let(:pal) { nil }
let(:plugins) { Bolt::Plugin.new(config, pal) }
let(:inventory) { Bolt::Inventory.create_version(data, config.transport, config.transports, plugins) }
let(:tasks_enabled) { true }
let(:target1) { 'target1' }
let(:target2) { 'target2' }
let(:parent) { 'group1' }
let(:child) { 'group2' }
let(:data) do
{ 'groups' => [
{ 'name' => parent,
'targets' => [target1],
'groups' => [
{ 'name' => child,
'targets' => [target1, target2] }
] }
] }
end
around(:each) do |example|
Puppet[:tasks] = tasks_enabled
Puppet.override(bolt_executor: executor, bolt_inventory: inventory) do
example.run
end
end
it 'errors when passed invalid data types' do
is_expected.to run.with_params(target1, 1)
.and_raise_error(ArgumentError,
"'remove_from_group' parameter 'group' expects a String value, got Integer")
end
it 'reports the call to analytics' do
executor.expects(:report_function_call).with('remove_from_group')
is_expected.to run.with_params(target1, parent)
end
context 'without tasks enabled' do
let(:tasks_enabled) { false }
it 'fails and reports that remove_from_group is not available' do
is_expected.to run.with_params(target1, parent)
.and_raise_error(/Plan language function 'remove_from_group' cannot be used/)
end
end
context 'removing target from a group' do
it 'errors when removing multiple targets' do
is_expected.to run.with_params(%w[foo bar], 'group1')
.and_raise_error(Bolt::Inventory::ValidationError,
"'remove_from_group' expects a single Target, got 2")
end
it "errors when removing targets from 'all' group" do
is_expected.to run.with_params(target1, 'all')
.and_raise_error(Bolt::Inventory::ValidationError,
"Cannot remove Target from Group 'all'")
end
it 'removes target from the specified group' do
is_expected.to run.with_params(target1, child)
targets = inventory.get_targets(child).map(&:name)
expect(targets).not_to include(target1)
end
it 'removes target from child groups' do
is_expected.to run.with_params(target1, parent)
targets = inventory.get_targets(child).map(&:name)
expect(targets).not_to include(target1)
end
it 'removes target from parent groups' do
is_expected.to run.with_params(target2, child)
targets = inventory.get_targets(parent).map(&:name)
expect(targets).not_to include(target2)
end
it 'does not remove targets from parent groups that also define the target' do
is_expected.to run.with_params(target1, child)
targets = inventory.get_targets(parent).map(&:name)
expect(targets).to include(target1)
end
end
end