beaker 1.21.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/CONTRIBUTING.md +1 -0
- data/HISTORY.md +17288 -2
- data/Rakefile +6 -2
- data/beaker.gemspec +15 -19
- data/lib/beaker.rb +2 -5
- data/lib/beaker/answers.rb +2 -0
- data/lib/beaker/answers/version34.rb +37 -1
- data/lib/beaker/cli.rb +4 -0
- data/lib/beaker/command.rb +16 -84
- data/lib/beaker/command_factory.rb +13 -2
- data/lib/beaker/dsl/assertions.rb +25 -2
- data/lib/beaker/dsl/ezbake_utils.rb +2 -2
- data/lib/beaker/dsl/helpers.rb +66 -12
- data/lib/beaker/dsl/install_utils.rb +128 -66
- data/lib/beaker/dsl/wrappers.rb +41 -3
- data/lib/beaker/host.rb +42 -6
- data/lib/beaker/host/mac.rb +62 -0
- data/lib/beaker/host/mac/group.rb +96 -0
- data/lib/beaker/host/mac/user.rb +93 -0
- data/lib/beaker/host/unix/exec.rb +1 -1
- data/lib/beaker/host/unix/pkg.rb +11 -11
- data/lib/beaker/host/windows.rb +4 -4
- data/lib/beaker/host_prebuilt_steps.rb +194 -58
- data/lib/beaker/hypervisor.rb +16 -9
- data/lib/beaker/hypervisor/aws_sdk.rb +61 -17
- data/lib/beaker/hypervisor/docker.rb +14 -2
- data/lib/beaker/hypervisor/ec2_helper.rb +15 -3
- data/lib/beaker/hypervisor/vagrant.rb +22 -10
- data/lib/beaker/hypervisor/vagrant_libvirt.rb +11 -0
- data/lib/beaker/hypervisor/vagrant_virtualbox.rb +1 -1
- data/lib/beaker/hypervisor/vcloud_pooled.rb +8 -39
- data/lib/beaker/logger.rb +15 -9
- data/lib/beaker/network_manager.rb +2 -2
- data/lib/beaker/options/command_line_parser.rb +1 -1
- data/lib/beaker/options/parser.rb +1 -8
- data/lib/beaker/options/presets.rb +70 -45
- data/lib/beaker/perf.rb +3 -4
- data/lib/beaker/platform.rb +2 -1
- data/lib/beaker/result.rb +3 -9
- data/lib/beaker/ssh_connection.rb +2 -0
- data/lib/beaker/test_case.rb +2 -21
- data/lib/beaker/test_suite.rb +21 -25
- data/lib/beaker/version.rb +1 -1
- data/spec/beaker/answers_spec.rb +36 -0
- data/spec/beaker/cli_spec.rb +45 -45
- data/spec/beaker/command_spec.rb +25 -36
- data/spec/beaker/dsl/assertions_spec.rb +20 -27
- data/spec/beaker/dsl/ezbake_utils_spec.rb +5 -5
- data/spec/beaker/dsl/helpers_spec.rb +293 -208
- data/spec/beaker/dsl/install_utils_spec.rb +310 -189
- data/spec/beaker/dsl/outcomes_spec.rb +6 -6
- data/spec/beaker/dsl/roles_spec.rb +27 -18
- data/spec/beaker/dsl/structure_spec.rb +11 -11
- data/spec/beaker/dsl/wrappers_spec.rb +35 -11
- data/spec/beaker/host/mac/group_spec.rb +124 -0
- data/spec/beaker/host/mac/user_spec.rb +134 -0
- data/spec/beaker/host/unix/pkg_spec.rb +40 -24
- data/spec/beaker/host/windows/group_spec.rb +1 -1
- data/spec/beaker/host_prebuilt_steps_spec.rb +194 -68
- data/spec/beaker/host_spec.rb +145 -67
- data/spec/beaker/hypervisor/aixer_spec.rb +6 -6
- data/spec/beaker/hypervisor/aws_sdk_spec.rb +22 -7
- data/spec/beaker/hypervisor/docker_spec.rb +71 -50
- data/spec/beaker/hypervisor/ec2_helper_spec.rb +25 -4
- data/spec/beaker/hypervisor/fusion_spec.rb +2 -2
- data/spec/beaker/hypervisor/hypervisor_spec.rb +20 -27
- data/spec/beaker/hypervisor/hypervisor_spec.rb.orig +80 -0
- data/spec/beaker/hypervisor/solaris_spec.rb +8 -8
- data/spec/beaker/hypervisor/vagrant_fusion_spec.rb +6 -8
- data/spec/beaker/hypervisor/vagrant_libvirt_spec.rb +34 -0
- data/spec/beaker/hypervisor/vagrant_spec.rb +34 -33
- data/spec/beaker/hypervisor/vagrant_virtualbox_spec.rb +18 -8
- data/spec/beaker/hypervisor/vagrant_workstation_spec.rb +6 -8
- data/spec/beaker/hypervisor/vcloud_pooled_spec.rb +8 -8
- data/spec/beaker/hypervisor/vcloud_spec.rb +10 -10
- data/spec/beaker/hypervisor/vsphere_helper_spec.rb +8 -8
- data/spec/beaker/hypervisor/vsphere_spec.rb +1 -1
- data/spec/beaker/logger_spec.rb +45 -31
- data/spec/beaker/options/command_line_parser_spec.rb +10 -2
- data/spec/beaker/options/hosts_file_parser_spec.rb +9 -2
- data/spec/beaker/options/options_hash_spec.rb +2 -2
- data/spec/beaker/options/parser_spec.rb +2 -2
- data/spec/beaker/options/pe_version_scaper_spec.rb +6 -1
- data/spec/beaker/options/presets_spec.rb +11 -1
- data/spec/beaker/shared/error_handler_spec.rb +5 -5
- data/spec/beaker/shared/host_manager_spec.rb +3 -2
- data/spec/beaker/shared/repetition_spec.rb +18 -18
- data/spec/beaker/ssh_connection_spec.rb +33 -4
- data/spec/beaker/test_case_spec.rb +9 -9
- data/spec/beaker/test_suite_spec.rb +14 -14
- data/spec/helpers.rb +4 -4
- data/spec/matchers.rb +4 -4
- data/spec/mocks.rb +5 -1
- data/spec/spec_helper.rb +2 -8
- metadata +114 -80
- data/lib/beaker/hypervisor/blimper.rb +0 -108
- data/spec/beaker/hypervisor/blimper_spec.rb +0 -42
- data/spec/beaker/options/data/LATEST +0 -1
- data/spec/beaker/puppet_command_spec.rb +0 -161
- data/spec/mock_blimpy.rb +0 -48
|
@@ -6,11 +6,11 @@ end
|
|
|
6
6
|
|
|
7
7
|
describe ClassMixedWithDSLOutcomes do
|
|
8
8
|
let(:logger) { double }
|
|
9
|
-
before { subject.
|
|
9
|
+
before { allow( subject ).to receive( :logger ).and_return( logger ) }
|
|
10
10
|
|
|
11
11
|
describe '#pass_test' do
|
|
12
12
|
it "logs the notification passed to it and raises PassTest" do
|
|
13
|
-
logger.
|
|
13
|
+
expect( logger ).to receive( :notify ).with( /blah/ )
|
|
14
14
|
expect { subject.pass_test('blah') }.
|
|
15
15
|
to raise_error Beaker::DSL::Outcomes::PassTest
|
|
16
16
|
end
|
|
@@ -18,7 +18,7 @@ describe ClassMixedWithDSLOutcomes do
|
|
|
18
18
|
|
|
19
19
|
describe '#skip_test' do
|
|
20
20
|
it "logs the notification passed to it and raises SkipTest" do
|
|
21
|
-
logger.
|
|
21
|
+
expect( logger ).to receive( :notify ).with( /blah/ )
|
|
22
22
|
expect { subject.skip_test('blah') }.
|
|
23
23
|
to raise_error Beaker::DSL::Outcomes::SkipTest
|
|
24
24
|
end
|
|
@@ -26,7 +26,7 @@ describe ClassMixedWithDSLOutcomes do
|
|
|
26
26
|
|
|
27
27
|
describe '#pending_test' do
|
|
28
28
|
it "logs the notification passed to it and raises PendingTest" do
|
|
29
|
-
logger.
|
|
29
|
+
expect( logger ).to receive( :warn ).with( /blah/ )
|
|
30
30
|
expect { subject.pending_test('blah') }.
|
|
31
31
|
to raise_error Beaker::DSL::Outcomes::PendingTest
|
|
32
32
|
end
|
|
@@ -34,8 +34,8 @@ describe ClassMixedWithDSLOutcomes do
|
|
|
34
34
|
|
|
35
35
|
describe '#fail_test' do
|
|
36
36
|
it "logs the notification passed to it and raises FailTest" do
|
|
37
|
-
logger.
|
|
38
|
-
logger.
|
|
37
|
+
expect( logger ).to receive( :warn )
|
|
38
|
+
expect( logger ).to receive( :pretty_backtrace )
|
|
39
39
|
expect { subject.fail_test('blah') }.
|
|
40
40
|
to raise_error Beaker::DSL::Outcomes::FailTest
|
|
41
41
|
end
|
|
@@ -21,76 +21,76 @@ describe ClassMixedWithDSLRoles do
|
|
|
21
21
|
describe '#agents' do
|
|
22
22
|
it 'returns an array of hosts that are agents' do
|
|
23
23
|
@hosts = [ agent1, agent2, master ]
|
|
24
|
-
subject.
|
|
24
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
25
25
|
expect( subject.agents ).to be == [ agent1, agent2, master ]
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it 'and an empty array when none match' do
|
|
29
29
|
@hosts = [ db, custom ]
|
|
30
|
-
subject.
|
|
30
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
31
31
|
expect( subject.agents ).to be == []
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
describe '#master' do
|
|
35
35
|
it 'returns the master if there is one' do
|
|
36
36
|
@hosts = [ master, agent1 ]
|
|
37
|
-
subject.
|
|
37
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
38
38
|
expect( subject.master ).to be == master
|
|
39
39
|
end
|
|
40
40
|
it 'raises an error if there is more than one master' do
|
|
41
41
|
@hosts = [ master, monolith ]
|
|
42
|
-
subject.
|
|
42
|
+
expect( subject ).to receive( :hosts ).exactly( 1 ).times.and_return( hosts )
|
|
43
43
|
expect { subject.master }.to raise_error Beaker::DSL::FailTest
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
describe '#dashboard' do
|
|
47
47
|
it 'returns the dashboard if there is one' do
|
|
48
48
|
@hosts = [ a_and_dash, agent1 ]
|
|
49
|
-
subject.
|
|
49
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
50
50
|
expect( subject.dashboard ).to be == a_and_dash
|
|
51
51
|
end
|
|
52
52
|
it 'raises an error if there is more than one dashboard' do
|
|
53
53
|
@hosts = [ a_and_dash, monolith ]
|
|
54
|
-
subject.
|
|
54
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
55
55
|
expect { subject.dashboard }.to raise_error Beaker::DSL::FailTest
|
|
56
56
|
end
|
|
57
57
|
it 'and raises an error if there is no dashboard' do
|
|
58
58
|
@hosts = [ agent1, agent2, custom ]
|
|
59
|
-
subject.
|
|
59
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
60
60
|
expect { subject.dashboard }.to raise_error Beaker::DSL::FailTest
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
describe '#database' do
|
|
64
64
|
it 'returns the database if there is one' do
|
|
65
65
|
@hosts = [ db, agent1 ]
|
|
66
|
-
subject.
|
|
66
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
67
67
|
expect( subject.database ).to be == db
|
|
68
68
|
end
|
|
69
69
|
it 'raises an error if there is more than one database' do
|
|
70
70
|
@hosts = [ db, monolith ]
|
|
71
|
-
subject.
|
|
71
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
72
72
|
expect { subject.database }.to raise_error Beaker::DSL::FailTest
|
|
73
73
|
end
|
|
74
74
|
it 'and raises an error if there is no database' do
|
|
75
75
|
@hosts = [ agent1, agent2, custom ]
|
|
76
|
-
subject.
|
|
76
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
77
77
|
expect { subject.database }.to raise_error Beaker::DSL::FailTest
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
80
|
describe '#default' do
|
|
81
81
|
it 'returns the default host when one is specified' do
|
|
82
82
|
@hosts = [ db, agent1, agent2, default, master]
|
|
83
|
-
subject.
|
|
83
|
+
expect( subject ).to receive( :hosts ).exactly( 1 ).times.and_return( hosts )
|
|
84
84
|
expect( subject.default ).to be == default
|
|
85
85
|
end
|
|
86
86
|
it 'raises an error if there is more than one default' do
|
|
87
87
|
@hosts = [ db, monolith, default, default ]
|
|
88
|
-
subject.
|
|
88
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
89
89
|
expect { subject.database }.to raise_error Beaker::DSL::FailTest
|
|
90
90
|
end
|
|
91
91
|
it 'and raises an error if there is no default' do
|
|
92
92
|
@hosts = [ agent1, agent2, custom ]
|
|
93
|
-
subject.
|
|
93
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
94
94
|
expect { subject.database }.to raise_error Beaker::DSL::FailTest
|
|
95
95
|
end
|
|
96
96
|
end
|
|
@@ -107,26 +107,35 @@ describe ClassMixedWithDSLRoles do
|
|
|
107
107
|
it 'creates new method for role "role_correct!"' do
|
|
108
108
|
test_role = "role_correct!"
|
|
109
109
|
subject.add_role_def( test_role )
|
|
110
|
-
subject.
|
|
110
|
+
expect( subject ).to respond_to test_role
|
|
111
111
|
subject.class.send( :undef_method, test_role )
|
|
112
112
|
end
|
|
113
113
|
it 'returns a single node for a new method for a role defined in a single node' do
|
|
114
114
|
@hosts = [ agent1, agent2, monolith ]
|
|
115
|
-
subject.
|
|
115
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
116
116
|
test_role = "custom_role"
|
|
117
117
|
subject.add_role_def( test_role )
|
|
118
|
-
subject.
|
|
118
|
+
expect( subject ).to respond_to test_role
|
|
119
119
|
expect( subject.send( test_role )).to be == @hosts[2]
|
|
120
120
|
subject.class.send( :undef_method, test_role )
|
|
121
121
|
end
|
|
122
122
|
it 'returns an array of nodes for a new method for a role defined in multiple nodes' do
|
|
123
123
|
@hosts = [ agent1, agent2, monolith, custom ]
|
|
124
|
-
subject.
|
|
124
|
+
expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
125
125
|
test_role = "custom_role"
|
|
126
126
|
subject.add_role_def( test_role )
|
|
127
|
-
subject.
|
|
127
|
+
expect( subject ).to respond_to test_role
|
|
128
128
|
expect( subject.send( test_role )).to be == [@hosts[2], @hosts[3]]
|
|
129
129
|
subject.class.send( :undef_method, test_role )
|
|
130
130
|
end
|
|
131
131
|
end
|
|
132
|
+
describe '#any_hosts_as?' do
|
|
133
|
+
it 'returns true if a host exists, false otherwise' do
|
|
134
|
+
@hosts = [ agent1, agent2 ]
|
|
135
|
+
# expect( subject ).to receive( :hosts ).and_return( hosts )
|
|
136
|
+
expect( subject ).to receive( :hosts ).exactly( 2 ).times.and_return( hosts )
|
|
137
|
+
expect( subject.any_hosts_as?( "agent" )).to be == true
|
|
138
|
+
expect( subject.any_hosts_as?( "custom_role" )).to be == false
|
|
139
|
+
end
|
|
140
|
+
end
|
|
132
141
|
end
|
|
@@ -12,15 +12,15 @@ describe ClassMixedWithDSLStructure do
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it 'notifies the logger' do
|
|
15
|
-
subject.
|
|
16
|
-
logger.
|
|
15
|
+
expect( subject ).to receive( :logger ).and_return( logger )
|
|
16
|
+
expect( logger ).to receive( :notify )
|
|
17
17
|
subject.step 'blah'
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it 'yields if a block is given' do
|
|
21
|
-
subject.
|
|
22
|
-
logger.
|
|
23
|
-
subject.
|
|
21
|
+
expect( subject ).to receive( :logger ).and_return( logger )
|
|
22
|
+
expect( logger ).to receive( :notify )
|
|
23
|
+
expect( subject ).to receive( :foo )
|
|
24
24
|
subject.step 'blah' do
|
|
25
25
|
subject.foo
|
|
26
26
|
end
|
|
@@ -33,15 +33,15 @@ describe ClassMixedWithDSLStructure do
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it 'notifies the logger' do
|
|
36
|
-
subject.
|
|
37
|
-
logger.
|
|
36
|
+
expect( subject ).to receive( :logger ).and_return( logger )
|
|
37
|
+
expect( logger ).to receive( :notify )
|
|
38
38
|
subject.test_name 'blah'
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it 'yields if a block is given' do
|
|
42
|
-
subject.
|
|
43
|
-
logger.
|
|
44
|
-
subject.
|
|
42
|
+
expect( subject ).to receive( :logger ).and_return( logger )
|
|
43
|
+
expect( logger ).to receive( :notify )
|
|
44
|
+
expect( subject ).to receive( :foo )
|
|
45
45
|
subject.test_name 'blah' do
|
|
46
46
|
subject.foo
|
|
47
47
|
end
|
|
@@ -53,7 +53,7 @@ describe ClassMixedWithDSLStructure do
|
|
|
53
53
|
teardown_array = double
|
|
54
54
|
subject.instance_variable_set :@teardown_procs, teardown_array
|
|
55
55
|
block = lambda { 'blah' }
|
|
56
|
-
teardown_array.
|
|
56
|
+
expect( teardown_array ).to receive( :<< ).with( block )
|
|
57
57
|
subject.teardown &block
|
|
58
58
|
end
|
|
59
59
|
end
|
|
@@ -5,30 +5,38 @@ class ClassMixedWithDSLWrappers
|
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
describe ClassMixedWithDSLWrappers do
|
|
8
|
-
let(:opts)
|
|
9
|
-
let(:
|
|
8
|
+
let(:opts) { {'ENV' => { :HOME => "/"}, :cmdexe => true } }
|
|
9
|
+
let(:empty_opts) { {'ENV' => {}, :cmdexe => true } }
|
|
10
|
+
|
|
10
11
|
describe '#facter' do
|
|
11
12
|
it 'should split out the options and pass "facter" as first arg to Command' do
|
|
12
|
-
Beaker::Command.
|
|
13
|
-
with('facter', [ '-p' ],
|
|
13
|
+
expect( Beaker::Command ).to receive( :new ).
|
|
14
|
+
with('facter', [ '-p' ], empty_opts)
|
|
14
15
|
subject.facter( '-p' )
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
|
|
19
|
+
describe '#cfacter' do
|
|
20
|
+
it 'should split out the options and pass "cfacter" as first arg to Command' do
|
|
21
|
+
expect( Beaker::Command ).to receive( :new ).
|
|
22
|
+
with('cfacter', [ '-p' ], empty_opts)
|
|
23
|
+
subject.cfacter( '-p' )
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
18
27
|
describe '#hiera' do
|
|
19
28
|
it 'should split out the options and pass "hiera" as first arg to Command' do
|
|
20
|
-
Beaker::Command.
|
|
21
|
-
with('hiera', [ '-p' ],
|
|
29
|
+
expect( Beaker::Command ).to receive( :new ).
|
|
30
|
+
with('hiera', [ '-p' ], empty_opts)
|
|
22
31
|
subject.hiera( '-p' )
|
|
23
32
|
end
|
|
24
33
|
end
|
|
25
34
|
|
|
26
35
|
describe '#puppet' do
|
|
27
36
|
it 'should split out the options and pass "puppet <blank>" to Command' do
|
|
28
|
-
merged_opts =
|
|
29
|
-
merged_opts['ENV'] = {:HOME => '/'}.merge( default_opts )
|
|
37
|
+
merged_opts = opts
|
|
30
38
|
merged_opts[:server] = 'master'
|
|
31
|
-
Beaker::Command.
|
|
39
|
+
expect( Beaker::Command ).to receive( :new ).
|
|
32
40
|
with('puppet agent', [ '-tv' ], merged_opts)
|
|
33
41
|
subject.puppet( 'agent', '-tv', :server => 'master', 'ENV' => {:HOME => '/'})
|
|
34
42
|
end
|
|
@@ -36,7 +44,7 @@ describe ClassMixedWithDSLWrappers do
|
|
|
36
44
|
|
|
37
45
|
describe '#host_command' do
|
|
38
46
|
it 'delegates to HostCommand.new' do
|
|
39
|
-
Beaker::HostCommand.
|
|
47
|
+
expect( Beaker::HostCommand ).to receive( :new ).with( 'blah' )
|
|
40
48
|
subject.host_command( 'blah' )
|
|
41
49
|
end
|
|
42
50
|
end
|
|
@@ -44,9 +52,25 @@ describe ClassMixedWithDSLWrappers do
|
|
|
44
52
|
describe 'deprecated puppet wrappers' do
|
|
45
53
|
%w( resource doc kick cert apply master agent filebucket ).each do |sub|
|
|
46
54
|
it "#{sub} delegates the proper info to #puppet" do
|
|
47
|
-
subject.
|
|
55
|
+
expect( subject ).to receive( :puppet ).with( sub, 'blah' )
|
|
48
56
|
subject.send( "puppet_#{sub}", 'blah')
|
|
49
57
|
end
|
|
50
58
|
end
|
|
51
59
|
end
|
|
60
|
+
|
|
61
|
+
describe '#powershell' do
|
|
62
|
+
it 'should pass "powershell.exe <args> -Command <command>" to Command' do
|
|
63
|
+
command = subject.powershell("Set-Content -path 'fu.txt' -value 'fu'")
|
|
64
|
+
expect(command.command ).to be === 'powershell.exe'
|
|
65
|
+
expect( command.args).to be === ' -ExecutionPolicy Bypass -InputFormat None -NoLogo -NoProfile -NonInteractive -Command "Set-Content -path \'fu.txt\' -value \'fu\'"'
|
|
66
|
+
expect( command.options ).to be === {}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'should merge the arguments provided with the defaults' do
|
|
70
|
+
command = subject.powershell("Set-Content -path 'fu.txt' -value 'fu'", {'ExecutionPolicy' => 'Unrestricted'})
|
|
71
|
+
expect( command.command).to be === 'powershell.exe'
|
|
72
|
+
expect( command.args ).to be === ' -ExecutionPolicy Unrestricted -InputFormat None -NoLogo -NoProfile -NonInteractive -Command "Set-Content -path \'fu.txt\' -value \'fu\'"'
|
|
73
|
+
expect( command.options ).to be === {}
|
|
74
|
+
end
|
|
75
|
+
end
|
|
52
76
|
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class MacGroupTest
|
|
4
|
+
include Mac::Group
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
describe MacGroupTest do
|
|
8
|
+
let( :puppet1 ) do <<-EOS
|
|
9
|
+
name: puppet1
|
|
10
|
+
password: *
|
|
11
|
+
gid: 55
|
|
12
|
+
|
|
13
|
+
EOS
|
|
14
|
+
end
|
|
15
|
+
let( :puppet2 ) do <<-EOS
|
|
16
|
+
name: puppet2
|
|
17
|
+
password: *
|
|
18
|
+
gid: 56
|
|
19
|
+
|
|
20
|
+
EOS
|
|
21
|
+
end
|
|
22
|
+
let( :dscacheutil_list ) do <<-EOS
|
|
23
|
+
#{puppet1}
|
|
24
|
+
#{puppet2}
|
|
25
|
+
EOS
|
|
26
|
+
end
|
|
27
|
+
let( :command ) { 'ls' }
|
|
28
|
+
let( :host ) { double.as_null_object }
|
|
29
|
+
let( :result ) { Beaker::Result.new( host, command ) }
|
|
30
|
+
|
|
31
|
+
describe '#group_list' do
|
|
32
|
+
|
|
33
|
+
it 'returns group names list correctly' do
|
|
34
|
+
result.stdout = dscacheutil_list
|
|
35
|
+
expect( subject ).to receive( :execute ).and_yield(result)
|
|
36
|
+
expect( subject.group_list ).to be === ['puppet1', 'puppet2']
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'yields correctly with the result object' do
|
|
40
|
+
result.stdout = dscacheutil_list
|
|
41
|
+
expect( subject ).to receive( :execute ).and_yield(result)
|
|
42
|
+
subject.group_list { |result|
|
|
43
|
+
expect( result.stdout ).to be === dscacheutil_list
|
|
44
|
+
}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe '#group_get' do
|
|
50
|
+
|
|
51
|
+
it 'fails if a name line isn\'t included' do
|
|
52
|
+
result.stdout = ''
|
|
53
|
+
group_name = 'any_name'
|
|
54
|
+
expect( subject ).to receive( :execute ).and_yield(result)
|
|
55
|
+
expect { subject.group_get(group_name) }.to raise_error(MiniTest::Assertion, "failed to get group #{group_name}")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'parses mac dscacheutil output into /etc/group format correctly' do
|
|
59
|
+
result.stdout = puppet1
|
|
60
|
+
expect( subject ).to receive( :execute ).and_yield(result)
|
|
61
|
+
subject.group_get('puppet1') do |answer|
|
|
62
|
+
expect(answer).to be === 'puppet1:*:55'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe '#group_gid' do
|
|
69
|
+
|
|
70
|
+
it 'parses mac dscacheutil output into the gid correctly' do
|
|
71
|
+
result.stdout = puppet1
|
|
72
|
+
expect( subject ).to receive( :execute ).and_yield(result)
|
|
73
|
+
expect( subject.group_gid(puppet1) ).to be === '55'
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'returns -1 if gid not found' do
|
|
77
|
+
result.stdout = ''
|
|
78
|
+
expect( subject ).to receive( :execute ).and_yield(result)
|
|
79
|
+
expect( subject.group_gid(puppet1) ).to be === -1
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe '#group_present' do
|
|
85
|
+
|
|
86
|
+
it 'returns group existence without running create command if it already exists' do
|
|
87
|
+
result.stdout = puppet1
|
|
88
|
+
expect( subject ).to receive( :execute ).once.and_yield(result)
|
|
89
|
+
subject.group_present( 'puppet1' )
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'runs correct create command if group does not exist' do
|
|
93
|
+
result.stdout = ''
|
|
94
|
+
gid = 512
|
|
95
|
+
name = "madeup_group"
|
|
96
|
+
|
|
97
|
+
expect( subject ).to receive( :gid_next ).and_return(gid)
|
|
98
|
+
expect( subject ).to receive( :execute ).once.ordered.and_yield(result)
|
|
99
|
+
expect( subject ).to receive( :execute ).with("dscl . create /Groups/#{name} && dscl . create /Groups/#{name} PrimaryGroupID #{gid}").once.ordered
|
|
100
|
+
subject.group_present( name )
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe '#group_absent' do
|
|
106
|
+
|
|
107
|
+
it 'calls execute to run logic' do
|
|
108
|
+
name = "main_one"
|
|
109
|
+
expect( subject ).to receive( :execute ).once.with("if dscl . -list /Groups/#{name}; then dscl . -delete /Groups/#{name}; fi", {})
|
|
110
|
+
subject.group_absent( name )
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe '#gid_next' do
|
|
116
|
+
|
|
117
|
+
it 'returns the next ID given' do
|
|
118
|
+
n = 10
|
|
119
|
+
expect( subject ).to receive( :execute ).and_return("#{n}")
|
|
120
|
+
expect( subject.gid_next ).to be === n + 1
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class MacUserTest
|
|
4
|
+
include Mac::User
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
describe MacUserTest do
|
|
8
|
+
let( :puppet1 ) do <<-EOS
|
|
9
|
+
name: puppet1
|
|
10
|
+
password: *
|
|
11
|
+
uid: 67
|
|
12
|
+
gid: 234
|
|
13
|
+
dir: /Users/puppet1
|
|
14
|
+
shell: /bin/bash
|
|
15
|
+
gecos: Unprivileged User
|
|
16
|
+
|
|
17
|
+
EOS
|
|
18
|
+
end
|
|
19
|
+
let( :puppet2 ) do <<-EOS
|
|
20
|
+
name: puppet2
|
|
21
|
+
password: *
|
|
22
|
+
uid: 68
|
|
23
|
+
gid: 235
|
|
24
|
+
dir: /Users/puppet2
|
|
25
|
+
shell: /bin/sh
|
|
26
|
+
gecos: puppet
|
|
27
|
+
|
|
28
|
+
EOS
|
|
29
|
+
end
|
|
30
|
+
let( :dscacheutil_list ) do <<-EOS
|
|
31
|
+
#{puppet1}
|
|
32
|
+
#{puppet2}
|
|
33
|
+
EOS
|
|
34
|
+
end
|
|
35
|
+
let( :command ) { 'ls' }
|
|
36
|
+
let( :host ) { double.as_null_object }
|
|
37
|
+
let( :result ) { Beaker::Result.new( host, command ) }
|
|
38
|
+
|
|
39
|
+
describe '#user_list' do
|
|
40
|
+
|
|
41
|
+
it 'returns user names list correctly' do
|
|
42
|
+
result.stdout = dscacheutil_list
|
|
43
|
+
expect( subject ).to receive( :execute ).and_yield(result)
|
|
44
|
+
expect( subject.user_list ).to be === ['puppet1', 'puppet2']
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'yields correctly with the result object' do
|
|
48
|
+
result.stdout = dscacheutil_list
|
|
49
|
+
expect( subject ).to receive( :execute ).and_yield(result)
|
|
50
|
+
subject.user_list { |result|
|
|
51
|
+
expect( result.stdout ).to be === dscacheutil_list
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe '#user_get' do
|
|
58
|
+
|
|
59
|
+
it 'fails if a name line isn\'t included' do
|
|
60
|
+
result.stdout = ''
|
|
61
|
+
user_name = 'any_name'
|
|
62
|
+
expect( subject ).to receive( :execute ).and_yield(result)
|
|
63
|
+
expect { subject.user_get(user_name) }.to raise_error(MiniTest::Assertion, "failed to get user #{user_name}")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'parses mac dscacheutil output into /etc/passwd format correctly' do
|
|
67
|
+
result.stdout = puppet1
|
|
68
|
+
expect( subject ).to receive( :execute ).and_yield(result)
|
|
69
|
+
expect( subject.user_get('puppet1') ).to be === "puppet1:*:67:234:puppet1:/Users/puppet1:/bin/bash"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'yields correctly with the result object' do
|
|
73
|
+
result.stdout = puppet1
|
|
74
|
+
expect( subject ).to receive( :execute ).and_yield(result)
|
|
75
|
+
subject.user_get('puppet1') do |result|
|
|
76
|
+
expect( result.stdout ).to be === puppet1
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe '#user_present' do
|
|
83
|
+
|
|
84
|
+
it 'returns user existence without running create command if it already exists' do
|
|
85
|
+
result.stdout = puppet1
|
|
86
|
+
expect( subject ).to receive( :execute ).once.and_yield(result)
|
|
87
|
+
subject.user_present( 'puppet1' )
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'runs correct create command if group does not exist' do
|
|
91
|
+
result.stdout = ''
|
|
92
|
+
uid = 512
|
|
93
|
+
gid = 1007
|
|
94
|
+
name = "madeup_user"
|
|
95
|
+
|
|
96
|
+
expect( subject ).to receive( :uid_next ).and_return(uid)
|
|
97
|
+
expect( subject ).to receive( :gid_next ).and_return(gid)
|
|
98
|
+
expect( subject ).to receive( :execute ).once.ordered.and_yield(result)
|
|
99
|
+
expect( subject ).to receive( :execute ).once.ordered
|
|
100
|
+
subject.user_present( name )
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe '#user_absent' do
|
|
106
|
+
|
|
107
|
+
it 'calls execute to run logic' do
|
|
108
|
+
name = "main_one"
|
|
109
|
+
expect( subject ).to receive( :execute ).once.with("if dscl . -list /Users/#{name}; then dscl . -delete /Users/#{name}; fi", {})
|
|
110
|
+
subject.user_absent( name )
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe '#uid_next' do
|
|
116
|
+
|
|
117
|
+
it 'returns the next ID given' do
|
|
118
|
+
n = 117
|
|
119
|
+
expect( subject ).to receive( :execute ).and_return("#{n}")
|
|
120
|
+
expect( subject.uid_next ).to be === n + 1
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe '#gid_next' do
|
|
126
|
+
|
|
127
|
+
it 'returns the next ID given' do
|
|
128
|
+
n = 843
|
|
129
|
+
expect( subject ).to receive( :execute ).and_return("#{n}")
|
|
130
|
+
expect( subject.gid_next ).to be === n + 1
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
end
|
|
134
|
+
end
|