mcollective-client 2.2.4 → 2.4.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.
Potentially problematic release.
This version of mcollective-client might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/lib/mcollective/application.rb +25 -34
- data/lib/mcollective/client.rb +91 -33
- data/lib/mcollective/config.rb +42 -43
- data/lib/mcollective/data/base.rb +1 -1
- data/lib/mcollective/data/result.rb +6 -2
- data/lib/mcollective/ddl/agentddl.rb +28 -1
- data/lib/mcollective/ddl/base.rb +8 -6
- data/lib/mcollective/log.rb +11 -3
- data/lib/mcollective/logger/file_logger.rb +4 -4
- data/lib/mcollective/matcher.rb +9 -1
- data/lib/mcollective/message.rb +14 -23
- data/lib/mcollective/optionparser.rb +9 -1
- data/lib/mcollective/pluginpackager.rb +24 -3
- data/lib/mcollective/pluginpackager/agent_definition.rb +12 -12
- data/lib/mcollective/pluginpackager/standard_definition.rb +12 -12
- data/lib/mcollective/rpc/agent.rb +15 -12
- data/lib/mcollective/rpc/client.rb +67 -31
- data/lib/mcollective/rpc/helpers.rb +7 -1
- data/lib/mcollective/rpc/reply.rb +3 -1
- data/lib/mcollective/shell.rb +45 -8
- data/lib/mcollective/util.rb +37 -1
- data/lib/mcollective/windows_daemon.rb +14 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/application_spec.rb +45 -26
- data/spec/unit/cache_spec.rb +3 -3
- data/spec/unit/client_spec.rb +269 -24
- data/spec/unit/config_spec.rb +89 -26
- data/spec/unit/data/base_spec.rb +1 -0
- data/spec/unit/data/result_spec.rb +19 -1
- data/spec/unit/data_spec.rb +3 -0
- data/spec/unit/ddl/agentddl_spec.rb +32 -0
- data/spec/unit/ddl/base_spec.rb +4 -0
- data/spec/unit/ddl/dataddl_spec.rb +1 -1
- data/spec/unit/log_spec.rb +44 -27
- data/spec/unit/logger/base_spec.rb +1 -1
- data/spec/unit/matcher_spec.rb +14 -0
- data/spec/unit/message_spec.rb +24 -0
- data/spec/unit/optionparser_spec.rb +99 -0
- data/spec/unit/pluginpackager/agent_definition_spec.rb +48 -17
- data/spec/unit/pluginpackager/standard_definition_spec.rb +44 -20
- data/spec/unit/pluginpackager_spec.rb +31 -7
- data/spec/unit/plugins/mcollective/agent/rpcutil_spec.rb +176 -0
- data/spec/unit/plugins/mcollective/application/plugin_spec.rb +81 -0
- data/spec/unit/plugins/mcollective/audit/logfile_spec.rb +44 -0
- data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +118 -27
- data/spec/unit/plugins/mcollective/connector/rabbitmq_spec.rb +168 -34
- data/spec/unit/plugins/mcollective/data/agent_data_spec.rb +1 -0
- data/spec/unit/plugins/mcollective/data/fstat_data_spec.rb +1 -0
- data/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb +10 -0
- data/spec/unit/plugins/mcollective/discovery/stdin_spec.rb +65 -0
- data/spec/unit/plugins/mcollective/facts/yaml_facts_spec.rb +65 -0
- data/spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb +240 -219
- data/spec/unit/plugins/mcollective/packagers/modulepackage_packager_spec.rb +209 -0
- data/spec/unit/plugins/mcollective/packagers/rpmpackage_packager_spec.rb +223 -109
- data/spec/unit/rpc/actionrunner_spec.rb +2 -1
- data/spec/unit/rpc/agent_spec.rb +130 -1
- data/spec/unit/rpc/client_spec.rb +169 -3
- data/spec/unit/security/base_spec.rb +0 -1
- data/spec/unit/shell_spec.rb +76 -3
- data/spec/unit/util_spec.rb +69 -1
- data/spec/unit/windows_daemon_spec.rb +30 -9
- metadata +104 -90
- data/spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb +0 -34
- data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +0 -424
- data/spec/unit/plugins/mcollective/validator/any_validator_spec.rb +0 -15
@@ -6,304 +6,325 @@ module MCollective
|
|
6
6
|
module PluginPackager
|
7
7
|
describe DebpackagePackager, :unless => MCollective::Util.windows? do
|
8
8
|
|
9
|
-
let(:
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
let(:plugin) do
|
10
|
+
plugin = mock
|
11
|
+
plugin.stubs(:mcname).returns('mcollective')
|
12
|
+
plugin.stubs(:metadata).returns({ :name => 'rspec', :version => '1.0'})
|
13
|
+
plugin.stubs(:target_path).returns('/rspec')
|
14
|
+
plugin
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
let(:packager) do
|
18
|
+
p = DebpackagePackager.new(plugin)
|
19
|
+
p.instance_variable_set(:@plugin, plugin)
|
20
|
+
p.instance_variable_set(:@tmpdir, 'rspec_tmp')
|
21
|
+
p.instance_variable_set(:@build_dir, 'rspec_build')
|
22
|
+
p.instance_variable_set(:@libdir, 'rspec_libdir')
|
23
|
+
p
|
17
24
|
end
|
18
25
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
26
|
+
let(:data) do
|
27
|
+
{:files => ['/rspec/agent/file.rb', '/rspec/agent/file.ddl', '/rspec/application/file.rb'],
|
28
|
+
:dependencies => [{:name => 'dep1', :version => nil, :revision => nil},
|
29
|
+
{:name => 'dep2', :version => '1.1', :revision => nil},
|
30
|
+
{:name => 'dep3', :version => '1.1', :revision => 2}],
|
31
|
+
:plugindependency => {:name => 'mcollective-rspec-common'}}
|
23
32
|
end
|
24
33
|
|
25
|
-
|
26
|
-
|
34
|
+
before :each do
|
35
|
+
PluginPackager.stubs(:command_available?).returns(true)
|
27
36
|
end
|
28
37
|
|
29
|
-
describe
|
30
|
-
it
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
describe '#initialize' do
|
39
|
+
it 'should set the instance variables' do
|
40
|
+
new_packager = DebpackagePackager.new(plugin)
|
41
|
+
new_packager.instance_variable_get(:@plugin).should == plugin
|
42
|
+
new_packager.instance_variable_get(:@verbose).should == false
|
43
|
+
new_packager.instance_variable_get(:@libdir).should == '/usr/share/mcollective/plugins/mcollective/'
|
44
|
+
new_packager.instance_variable_get(:@signature).should == nil
|
45
|
+
new_packager.instance_variable_get(:@package_name).should == 'mcollective-rspec'
|
35
46
|
end
|
36
47
|
|
37
|
-
it
|
38
|
-
PluginPackager.
|
39
|
-
|
40
|
-
|
41
|
-
|
48
|
+
it 'should fail if debuild is not present on the system' do
|
49
|
+
PluginPackager.stubs(:command_available?).with('debuild').returns(false)
|
50
|
+
expect{
|
51
|
+
DebpackagePackager.new(plugin)
|
52
|
+
}.to raise_error("Cannot build package. 'debuild' is not present on the system.")
|
42
53
|
end
|
43
54
|
end
|
44
55
|
|
45
|
-
describe
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
describe '#create_packages' do
|
57
|
+
it 'should run through the complete build process' do
|
58
|
+
build_dir = 'mc-tmp/mcollective-rspec_1.0'
|
59
|
+
tmpdir = 'mc-tmp'
|
60
|
+
packager.stubs(:puts)
|
61
|
+
Dir.expects(:mktmpdir).with('mcollective_packager').returns(tmpdir)
|
62
|
+
Dir.expects(:mkdir).with(build_dir)
|
63
|
+
packager.expects(:create_debian_dir)
|
64
|
+
plugin.stubs(:packagedata).returns({:agent => data})
|
65
|
+
packager.expects(:prepare_tmpdirs).with(data)
|
66
|
+
packager.expects(:create_install_file).with(:agent, data)
|
67
|
+
packager.expects(:create_pre_and_post_install).with(:agent)
|
68
|
+
packager.expects(:create_debian_files)
|
69
|
+
packager.expects(:create_tar)
|
70
|
+
packager.expects(:run_build)
|
71
|
+
packager.expects(:move_packages)
|
72
|
+
packager.expects(:cleanup_tmpdirs)
|
73
|
+
packager.create_packages
|
57
74
|
end
|
58
75
|
|
59
|
-
it
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
76
|
+
it 'should clean up tmpdirs if keep_artifacts is false' do
|
77
|
+
packager.stubs(:puts)
|
78
|
+
Dir.stubs(:mktmpdir).raises('error')
|
79
|
+
packager.expects(:cleanup_tmpdirs)
|
80
|
+
expect{
|
81
|
+
packager.create_packages
|
82
|
+
}.to raise_error('error')
|
65
83
|
end
|
66
84
|
|
67
|
-
it
|
68
|
-
|
69
|
-
|
85
|
+
it 'should keep the build artifacts if keep_artifacts is true' do
|
86
|
+
packager.instance_variable_set(:@keep_artifacts, true)
|
87
|
+
packager.stubs(:puts)
|
88
|
+
Dir.stubs(:mktmpdir).raises('error')
|
89
|
+
packager.expects(:cleanup_tmpdirs).never
|
90
|
+
expect{
|
91
|
+
packager.create_packages
|
92
|
+
}.to raise_error('error')
|
70
93
|
end
|
94
|
+
end
|
71
95
|
|
72
|
-
|
73
|
-
|
74
|
-
|
96
|
+
describe '#create_debian_files' do
|
97
|
+
it 'should create all the debian build files' do
|
98
|
+
['control', 'Makefile', 'compat', 'rules', 'copyright', 'changelog'].each do |f|
|
99
|
+
packager.expects(:create_file).with(f)
|
100
|
+
end
|
101
|
+
packager.send(:create_debian_files)
|
75
102
|
end
|
76
103
|
end
|
77
104
|
|
78
|
-
describe
|
79
|
-
it
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
}.to raise_error(RuntimeError, "Could not build package - test exception")
|
105
|
+
describe '#run_build' do
|
106
|
+
it 'should build the packages' do
|
107
|
+
FileUtils.expects(:cd).with('rspec_build').yields
|
108
|
+
PluginPackager.stubs(:do_quietly).with(false).yields
|
109
|
+
PluginPackager.expects(:safe_system).with('debuild --no-lintian -i -us -uc')
|
110
|
+
packager.send(:run_build)
|
85
111
|
end
|
86
112
|
|
87
|
-
it
|
88
|
-
packager
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
packager.
|
93
|
-
packager.expects(:create_file).with("rules")
|
94
|
-
packager.expects(:create_file).with("copyright")
|
95
|
-
packager.expects(:create_file).with("changelog")
|
96
|
-
packager.expects(:create_tar)
|
97
|
-
packager.expects(:create_install)
|
98
|
-
packager.expects(:create_preandpost_install)
|
99
|
-
|
100
|
-
packager.build_dir = "/tmp"
|
101
|
-
packager.tmpdir = "/tmp"
|
102
|
-
packager.current_package_fullname = "test"
|
103
|
-
PluginPackager.expects(:safe_system).with("debuild -i -us -uc")
|
104
|
-
packager.expects(:puts).with("Created package test")
|
105
|
-
|
106
|
-
packager.create_package
|
113
|
+
it 'should build the package and sign it with the set signature' do
|
114
|
+
packager.instance_variable_set(:@signature, '0x1234')
|
115
|
+
FileUtils.expects(:cd).with('rspec_build').yields
|
116
|
+
PluginPackager.stubs(:do_quietly).with(false).yields
|
117
|
+
PluginPackager.expects(:safe_system).with('debuild --no-lintian -i -k0x1234')
|
118
|
+
packager.send(:run_build)
|
107
119
|
end
|
108
120
|
|
109
|
-
it "should add a signature if one is given" do
|
110
|
-
packager = DebpackagePackager.new(@plugin, nil, "test", true)
|
111
121
|
|
112
|
-
|
113
|
-
packager.
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
packager.
|
118
|
-
packager.expects(:create_tar)
|
119
|
-
packager.expects(:create_install)
|
120
|
-
packager.expects(:create_preandpost_install)
|
121
|
-
|
122
|
-
packager.build_dir = "/tmp"
|
123
|
-
packager.tmpdir = "/tmp"
|
124
|
-
packager.current_package_fullname = "test"
|
125
|
-
PluginPackager.expects(:safe_system).with("debuild -i -ktest")
|
126
|
-
packager.expects(:puts).with("Created package test")
|
127
|
-
|
128
|
-
packager.create_package
|
122
|
+
it 'should sign with the exported gpg key' do
|
123
|
+
packager.instance_variable_set(:@signature, true)
|
124
|
+
FileUtils.expects(:cd).with('rspec_build').yields
|
125
|
+
PluginPackager.stubs(:do_quietly).with(false).yields
|
126
|
+
PluginPackager.expects(:safe_system).with('debuild --no-lintian -i')
|
127
|
+
packager.send(:run_build)
|
129
128
|
end
|
130
129
|
end
|
131
130
|
|
132
|
-
describe
|
133
|
-
|
134
|
-
|
131
|
+
describe '#build_dependency_string' do
|
132
|
+
it 'should create the correct dependency string' do
|
133
|
+
PluginPackager.expects(:filter_dependencies).with('debian', data[:dependencies]).returns(data[:dependencies])
|
134
|
+
result = packager.send(:build_dependency_string, data)
|
135
|
+
result.should == 'dep1, dep2 (>=1.1), dep3 (>=1.1-2), mcollective-rspec-common (= ${binary:Version})'
|
135
136
|
end
|
137
|
+
end
|
136
138
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
139
|
+
describe '#create_install_file' do
|
140
|
+
it 'should create the .install file in the correct location' do
|
141
|
+
file = mock
|
142
|
+
file.expects(:puts).with('rspec_libdir/agent/file.rb rspec_libdir/agent')
|
143
|
+
file.expects(:puts).with('rspec_libdir/agent/file.ddl rspec_libdir/agent')
|
144
|
+
file.expects(:puts).with('rspec_libdir/application/file.rb rspec_libdir/application')
|
145
|
+
File.expects(:open).with('rspec_build/debian/mcollective-rspec-agent.install', 'w').yields(file)
|
146
|
+
packager.send(:create_install_file, :agent, data)
|
143
147
|
end
|
144
148
|
|
145
|
-
it
|
146
|
-
|
147
|
-
|
148
|
-
File.expects(:exists?).with("myscript").returns(false)
|
149
|
+
it 'should write a message and raise an error if we do not have permission' do
|
150
|
+
File.expects(:open).with('rspec_build/debian/mcollective-rspec-agent.install', 'w').raises(Errno::EACCES)
|
151
|
+
packager.expects(:puts).with("Could not create install file 'rspec_build/debian/mcollective-rspec-agent.install'. Permission denied")
|
149
152
|
expect{
|
150
|
-
|
151
|
-
}.to raise_error(
|
153
|
+
packager.send(:create_install_file, :agent, data)
|
154
|
+
}.to raise_error(Errno::EACCES)
|
152
155
|
end
|
153
156
|
|
154
|
-
it
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
FileUtils.expects(:cp).with("myscript", "/tmp/debian/test.preinst")
|
161
|
-
FileUtils.expects(:cp).with("myscript", "/tmp/debian/test.postinst")
|
162
|
-
@packager.create_preandpost_install
|
157
|
+
it 'should write a message and raise an error if we cannot create the install file' do
|
158
|
+
File.expects(:open).with('rspec_build/debian/mcollective-rspec-agent.install', 'w').raises('error')
|
159
|
+
packager.expects(:puts).with("Could not create install file 'rspec_build/debian/mcollective-rspec-agent.install'.")
|
160
|
+
expect{
|
161
|
+
packager.send(:create_install_file, :agent, data)
|
162
|
+
}.to raise_error('error')
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
-
describe
|
167
|
-
|
168
|
-
|
169
|
-
|
166
|
+
describe '#move_packages' do
|
167
|
+
it 'should move the source package and debs to the cdw' do
|
168
|
+
files = ['rspec.deb', 'rspec.diff.gz', 'rspec.orig.tar.gz', 'rspec.changes']
|
169
|
+
Dir.stubs(:glob).returns(files)
|
170
|
+
FileUtils.expects(:cp).with(files, '.')
|
171
|
+
packager.send(:move_packages)
|
170
172
|
end
|
171
173
|
|
172
|
-
it
|
173
|
-
|
174
|
+
it 'should log an error and raise an error if the files cannot be moved' do
|
175
|
+
files = ['rspec.deb', 'rspec.diff.gz', 'rspec.orig.tar.gz', 'rspec.changes']
|
176
|
+
Dir.stubs(:glob).returns(files)
|
177
|
+
FileUtils.expects(:cp).with(files, '.').raises('error')
|
178
|
+
packager.expects(:puts).with('Could not copy packages to working directory.')
|
174
179
|
expect{
|
175
|
-
|
176
|
-
}.to raise_error(
|
177
|
-
end
|
178
|
-
|
179
|
-
it "should copy the package install file to the correct location" do
|
180
|
-
tmpdir = maketmpdir
|
181
|
-
Dir.mkdir(File.join(tmpdir, "debian"))
|
182
|
-
@packager.build_dir = tmpdir
|
183
|
-
@packager.current_package_shortname = "test"
|
184
|
-
@packager.current_package_data = {:files => ["foo.rb"]}
|
185
|
-
@packager.create_install
|
186
|
-
install_file = File.read("#{tmpdir}/debian/test.install")
|
187
|
-
install_file.should == "/usr/share/mcollective/plugins/mcollective/foo.rb /usr/share/mcollective/plugins/mcollective\n"
|
180
|
+
packager.send(:move_packages)
|
181
|
+
}.to raise_error('error')
|
188
182
|
end
|
189
183
|
end
|
190
184
|
|
191
|
-
describe
|
192
|
-
|
193
|
-
|
185
|
+
describe '#create_pre_and_post_install' do
|
186
|
+
it 'should create the pre-install file' do
|
187
|
+
plugin.stubs(:preinstall).returns('rspec-preinstall')
|
188
|
+
plugin.stubs(:postinstall).returns(nil)
|
189
|
+
File.expects(:exists?).with('rspec-preinstall').returns(true)
|
190
|
+
FileUtils.expects(:cp).with('rspec-preinstall', 'rspec_build/debian/mcollective-rspec-agent.preinst')
|
191
|
+
packager.send(:create_pre_and_post_install, :agent)
|
194
192
|
end
|
195
193
|
|
196
|
-
it
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
194
|
+
it 'should create the post-install file' do
|
195
|
+
plugin.stubs(:preinstall).returns(nil)
|
196
|
+
plugin.stubs(:postinstall).returns('rspec-postinstall')
|
197
|
+
File.expects(:exists?).with('rspec-postinstall').returns(true)
|
198
|
+
FileUtils.expects(:cp).with('rspec-postinstall', 'rspec_build/debian/mcollective-rspec-agent.postinst')
|
199
|
+
packager.send(:create_pre_and_post_install, :agent)
|
202
200
|
end
|
203
201
|
|
204
|
-
it
|
205
|
-
|
206
|
-
File.expects(:
|
202
|
+
it 'should fail if a pre-install script is defined but the file does not exist' do
|
203
|
+
plugin.stubs(:preinstall).returns('rspec-preinstall')
|
204
|
+
File.expects(:exists?).with('rspec-preinstall').returns(false)
|
205
|
+
packager.expects(:puts).with("pre-install script 'rspec-preinstall' not found.")
|
207
206
|
expect{
|
208
|
-
|
209
|
-
|
207
|
+
packager.send(:create_pre_and_post_install, :agent)
|
208
|
+
}.to raise_error(Errno::ENOENT, 'No such file or directory - rspec-preinstall')
|
210
209
|
end
|
211
|
-
end
|
212
210
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
it "should raise an exception if the tarball can't be built" do
|
219
|
-
PluginPackager.expects(:do_quietly?).raises("test error")
|
211
|
+
it 'should fail if a post-install script is defined but the file does not exist' do
|
212
|
+
plugin.stubs(:preinstall).returns(nil)
|
213
|
+
plugin.stubs(:postinstall).returns('rspec-postinstall')
|
214
|
+
File.expects(:exists?).with('rspec-postinstall').returns(false)
|
215
|
+
packager.expects(:puts).with("post-install script 'rspec-postinstall' not found.")
|
220
216
|
expect{
|
221
|
-
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
it "should create a tarball containing the package files" do
|
226
|
-
@packager.tmpdir = "/tmp"
|
227
|
-
@packager.build_dir = "/build_dir"
|
228
|
-
@packager.current_package_shortname = "test"
|
229
|
-
@plugin.stubs(:metadata).returns(@plugin)
|
230
|
-
@plugin.stubs(:[]).with(:version).returns("1")
|
231
|
-
@plugin.stubs(:iteration).returns("1")
|
232
|
-
PluginPackager.expects(:safe_system).with("tar -Pcvzf /tmp/test_1.orig.tar.gz test_1")
|
233
|
-
@packager.create_tar
|
217
|
+
packager.send(:create_pre_and_post_install, :agent)
|
218
|
+
}.to raise_error(Errno::ENOENT, 'No such file or directory - rspec-postinstall')
|
234
219
|
end
|
235
220
|
end
|
236
221
|
|
237
|
-
describe
|
238
|
-
|
239
|
-
|
222
|
+
describe '#create_tar' do
|
223
|
+
it 'should create the tarball' do
|
224
|
+
PluginPackager.stubs(:do_quietly?).yields
|
225
|
+
Dir.stubs(:chdir).with('rspec_tmp').yields
|
226
|
+
PluginPackager.expects(:safe_system).with('tar -Pcvzf rspec_tmp/mcollective-rspec_1.0.orig.tar.gz mcollective-rspec_1.0')
|
227
|
+
packager.send(:create_tar)
|
240
228
|
end
|
241
229
|
|
242
|
-
it
|
243
|
-
|
230
|
+
it 'should log an error and raise an exception if it cannot create the tarball' do
|
231
|
+
PluginPackager.stubs(:do_quietly?).yields
|
232
|
+
Dir.stubs(:chdir).with('rspec_tmp').yields
|
233
|
+
PluginPackager.expects(:safe_system).raises('error')
|
234
|
+
packager.expects(:puts).with("Could not create tarball - mcollective-rspec_1.0.orig.tar.gz")
|
244
235
|
expect{
|
245
|
-
|
246
|
-
}.to raise_error(
|
236
|
+
packager.send(:create_tar)
|
237
|
+
}.to raise_error('error')
|
247
238
|
end
|
239
|
+
end
|
248
240
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
File.
|
254
|
-
|
255
|
-
File.
|
256
|
-
|
257
|
-
|
258
|
-
|
241
|
+
describe '#create_file' do
|
242
|
+
it 'should create the named file in the build dir' do
|
243
|
+
file = mock
|
244
|
+
erb_content = mock
|
245
|
+
File.stubs(:read).returns('<%= "file content" %>')
|
246
|
+
ERB.expects(:new).with('<%= "file content" %>', nil, '-').returns(erb_content)
|
247
|
+
File.stubs(:open).with('rspec_build/debian/rspec', 'w').yields(file)
|
248
|
+
erb_content.expects(:result).returns('file content')
|
249
|
+
file.expects(:puts).with('file content')
|
250
|
+
packager.send(:create_file, 'rspec')
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'should log an error and raise if it cannot create the file' do
|
254
|
+
File.stubs(:read).returns('<%= "file content" %>')
|
255
|
+
ERB.stubs(:new).with('<%= "file content" %>', nil, '-').raises('error')
|
256
|
+
packager.expects(:puts).with("Could not create file - 'rspec'")
|
257
|
+
expect{
|
258
|
+
packager.send(:create_file, 'rspec')
|
259
|
+
}.to raise_error('error')
|
259
260
|
end
|
260
261
|
end
|
261
262
|
|
262
|
-
describe
|
263
|
-
|
264
|
-
|
263
|
+
describe '#prepare_tmpdirs' do
|
264
|
+
it 'should create the target directories and copy the files' do
|
265
|
+
FileUtils.expects(:mkdir_p).with('rspec_build/rspec_libdir/agent').twice
|
266
|
+
FileUtils.expects(:mkdir_p).with('rspec_build/rspec_libdir/application')
|
267
|
+
FileUtils.expects(:cp_r).with('/rspec/agent/file.rb', 'rspec_build/rspec_libdir/agent')
|
268
|
+
FileUtils.expects(:cp_r).with('/rspec/agent/file.ddl', 'rspec_build/rspec_libdir/agent')
|
269
|
+
FileUtils.expects(:cp_r).with('/rspec/application/file.rb', 'rspec_build/rspec_libdir/application')
|
270
|
+
packager.send(:prepare_tmpdirs, data)
|
265
271
|
end
|
266
272
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
273
|
+
it 'should log an error and raise if permissions means the dir cannot be created' do
|
274
|
+
FileUtils.stubs(:mkdir_p).with('rspec_build/rspec_libdir/agent').raises(Errno::EACCES)
|
275
|
+
packager.expects(:puts).with("Could not create directory 'rspec_build/rspec_libdir/agent'. Permission denied")
|
276
|
+
expect{
|
277
|
+
packager.send(:prepare_tmpdirs, data)
|
278
|
+
}.to raise_error(Errno::EACCES)
|
272
279
|
end
|
273
280
|
|
274
|
-
it
|
275
|
-
|
276
|
-
|
277
|
-
packager.
|
278
|
-
|
281
|
+
it 'should log an error and raise if the file does not exist' do
|
282
|
+
FileUtils.stubs(:mkdir_p)
|
283
|
+
FileUtils.expects(:cp_r).with('/rspec/agent/file.rb', 'rspec_build/rspec_libdir/agent').raises(Errno::ENOENT)
|
284
|
+
packager.expects(:puts).with("Could not copy file '/rspec/agent/file.rb' to 'rspec_build/rspec_libdir/agent'. File does not exist")
|
285
|
+
expect{
|
286
|
+
packager.send(:prepare_tmpdirs, data)
|
287
|
+
}.to raise_error(Errno::ENOENT)
|
288
|
+
end
|
279
289
|
|
280
|
-
|
281
|
-
File.
|
282
|
-
|
283
|
-
|
290
|
+
it 'should log an error and raise for any other exception' do
|
291
|
+
File.stubs(:expand_path).raises('error')
|
292
|
+
packager.expects(:puts).with('Could not prepare build directory')
|
293
|
+
expect{
|
294
|
+
packager.send(:prepare_tmpdirs, data)
|
295
|
+
}.to raise_error('error')
|
284
296
|
end
|
285
297
|
end
|
286
298
|
|
287
|
-
describe
|
288
|
-
|
289
|
-
|
299
|
+
describe '#create_debian_dir' do
|
300
|
+
it 'should create the debian dir in the build dir' do
|
301
|
+
FileUtils.expects(:mkdir_p).with('rspec_build/debian')
|
302
|
+
packager.send(:create_debian_dir)
|
290
303
|
end
|
291
304
|
|
292
|
-
|
293
|
-
|
305
|
+
it 'should log an error and raise an exception if the dir cannot be created' do
|
306
|
+
FileUtils.expects(:mkdir_p).with('rspec_build/debian').raises('error')
|
307
|
+
packager.expects(:puts).with("Could not create directory 'rspec_build/debian'")
|
308
|
+
expect{
|
309
|
+
packager.send(:create_debian_dir)
|
310
|
+
}.to raise_error('error')
|
294
311
|
end
|
312
|
+
end
|
295
313
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
314
|
+
describe '#cleanup_tmpdirs' do
|
315
|
+
it 'should remove the temporary build directory' do
|
316
|
+
File.stubs(:directory?).with('rspec_tmp').returns(true)
|
317
|
+
FileUtils.expects(:rm_r).with('rspec_tmp')
|
318
|
+
packager.send(:cleanup_tmpdirs)
|
300
319
|
end
|
301
320
|
|
302
|
-
it
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
321
|
+
it 'should log an error and raise an exception if the directory could not be removed' do
|
322
|
+
File.stubs(:directory?).with('rspec_tmp').returns(true)
|
323
|
+
FileUtils.expects(:rm_r).with('rspec_tmp').raises('error')
|
324
|
+
packager.expects(:puts).with("Could not remove temporary build directory - 'rspec_tmp'")
|
325
|
+
expect{
|
326
|
+
packager.send(:cleanup_tmpdirs)
|
327
|
+
}.to raise_error('error')
|
307
328
|
end
|
308
329
|
end
|
309
330
|
end
|