mcollective-client 2.2.4 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mcollective-client might be problematic. Click here for more details.

Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/lib/mcollective/application.rb +25 -34
  3. data/lib/mcollective/client.rb +91 -33
  4. data/lib/mcollective/config.rb +42 -43
  5. data/lib/mcollective/data/base.rb +1 -1
  6. data/lib/mcollective/data/result.rb +6 -2
  7. data/lib/mcollective/ddl/agentddl.rb +28 -1
  8. data/lib/mcollective/ddl/base.rb +8 -6
  9. data/lib/mcollective/log.rb +11 -3
  10. data/lib/mcollective/logger/file_logger.rb +4 -4
  11. data/lib/mcollective/matcher.rb +9 -1
  12. data/lib/mcollective/message.rb +14 -23
  13. data/lib/mcollective/optionparser.rb +9 -1
  14. data/lib/mcollective/pluginpackager.rb +24 -3
  15. data/lib/mcollective/pluginpackager/agent_definition.rb +12 -12
  16. data/lib/mcollective/pluginpackager/standard_definition.rb +12 -12
  17. data/lib/mcollective/rpc/agent.rb +15 -12
  18. data/lib/mcollective/rpc/client.rb +67 -31
  19. data/lib/mcollective/rpc/helpers.rb +7 -1
  20. data/lib/mcollective/rpc/reply.rb +3 -1
  21. data/lib/mcollective/shell.rb +45 -8
  22. data/lib/mcollective/util.rb +37 -1
  23. data/lib/mcollective/windows_daemon.rb +14 -3
  24. data/spec/spec_helper.rb +2 -0
  25. data/spec/unit/application_spec.rb +45 -26
  26. data/spec/unit/cache_spec.rb +3 -3
  27. data/spec/unit/client_spec.rb +269 -24
  28. data/spec/unit/config_spec.rb +89 -26
  29. data/spec/unit/data/base_spec.rb +1 -0
  30. data/spec/unit/data/result_spec.rb +19 -1
  31. data/spec/unit/data_spec.rb +3 -0
  32. data/spec/unit/ddl/agentddl_spec.rb +32 -0
  33. data/spec/unit/ddl/base_spec.rb +4 -0
  34. data/spec/unit/ddl/dataddl_spec.rb +1 -1
  35. data/spec/unit/log_spec.rb +44 -27
  36. data/spec/unit/logger/base_spec.rb +1 -1
  37. data/spec/unit/matcher_spec.rb +14 -0
  38. data/spec/unit/message_spec.rb +24 -0
  39. data/spec/unit/optionparser_spec.rb +99 -0
  40. data/spec/unit/pluginpackager/agent_definition_spec.rb +48 -17
  41. data/spec/unit/pluginpackager/standard_definition_spec.rb +44 -20
  42. data/spec/unit/pluginpackager_spec.rb +31 -7
  43. data/spec/unit/plugins/mcollective/agent/rpcutil_spec.rb +176 -0
  44. data/spec/unit/plugins/mcollective/application/plugin_spec.rb +81 -0
  45. data/spec/unit/plugins/mcollective/audit/logfile_spec.rb +44 -0
  46. data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +118 -27
  47. data/spec/unit/plugins/mcollective/connector/rabbitmq_spec.rb +168 -34
  48. data/spec/unit/plugins/mcollective/data/agent_data_spec.rb +1 -0
  49. data/spec/unit/plugins/mcollective/data/fstat_data_spec.rb +1 -0
  50. data/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb +10 -0
  51. data/spec/unit/plugins/mcollective/discovery/stdin_spec.rb +65 -0
  52. data/spec/unit/plugins/mcollective/facts/yaml_facts_spec.rb +65 -0
  53. data/spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb +240 -219
  54. data/spec/unit/plugins/mcollective/packagers/modulepackage_packager_spec.rb +209 -0
  55. data/spec/unit/plugins/mcollective/packagers/rpmpackage_packager_spec.rb +223 -109
  56. data/spec/unit/rpc/actionrunner_spec.rb +2 -1
  57. data/spec/unit/rpc/agent_spec.rb +130 -1
  58. data/spec/unit/rpc/client_spec.rb +169 -3
  59. data/spec/unit/security/base_spec.rb +0 -1
  60. data/spec/unit/shell_spec.rb +76 -3
  61. data/spec/unit/util_spec.rb +69 -1
  62. data/spec/unit/windows_daemon_spec.rb +30 -9
  63. metadata +104 -90
  64. data/spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb +0 -34
  65. data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +0 -424
  66. data/spec/unit/plugins/mcollective/validator/any_validator_spec.rb +0 -15
@@ -302,6 +302,30 @@ module MCollective
302
302
  end
303
303
  end
304
304
 
305
+ describe "#validate_compound_filter" do
306
+ let(:ddl) { mock }
307
+ let(:message) { Message.new("msg", "message", :type => :reply) }
308
+ let(:statement) { [{"fstatement" => {"name" => "rspec", "value" => "rspec_value", "params" => "rspec_param"} }] }
309
+
310
+ before do
311
+ Data.stubs(:pluginname).returns("rspec")
312
+ Data.stubs(:ddl_transform_input).with(ddl, "rspec_param").returns("rspec_param")
313
+ DDL.stubs(:new).returns(ddl)
314
+ Data.stubs(:ddl_validate).with(ddl, "rspec_param")
315
+ end
316
+
317
+ it "should correctly validate a compound filter" do
318
+ Data.stubs(:ddl_has_output?).with(ddl, "rspec_value").returns(true)
319
+ message.validate_compound_filter([statement])
320
+ end
321
+
322
+ it "should fail if an invalid value is queries" do
323
+ Data.stubs(:ddl_has_output?).with(ddl, "rspec_value").returns(false)
324
+ DDL.expects(:validation_fail!).with(:PLMC41, "Data plugin '%{functionname}()' does not return a '%{value}' value", :error, {:functionname => "rspec", :value => "rspec_value"})
325
+ message.validate_compound_filter([statement])
326
+ end
327
+ end
328
+
305
329
  describe "#validate" do
306
330
  it "should only validate requests" do
307
331
  m = Message.new("msg", "message", :type => :reply)
@@ -109,5 +109,104 @@ module MCollective
109
109
  parser.parse[:collective].should == :rspec
110
110
  end
111
111
  end
112
+
113
+ describe '#add_common_options' do
114
+ before :each do
115
+ @parser = Optionparser.new
116
+ end
117
+
118
+ after :each do
119
+ ARGV.pop
120
+ end
121
+
122
+ it 'should parse the --target option' do
123
+ ARGV << '--target=rspec_collective'
124
+ @parser.parse
125
+ @parser.instance_variable_get(:@options)[:collective].should == 'rspec_collective'
126
+ end
127
+
128
+ it 'should parse the --discovery-timeout option' do
129
+ ARGV << '--discovery-timeout=1'
130
+ @parser.parse
131
+ @parser.instance_variable_get(:@options)[:disctimeout].should == 1
132
+ end
133
+
134
+ it 'should parse the --timeout option' do
135
+ ARGV << '--timeout=5'
136
+ @parser.parse
137
+ @parser.instance_variable_get(:@options)[:timeout].should == 5
138
+ end
139
+
140
+ it 'should parse the --quiet option' do
141
+ ARGV << '--quiet'
142
+ @parser.parse
143
+ @parser.instance_variable_get(:@options)[:verbose].should == false
144
+ end
145
+
146
+ it 'should parse the --ttl option' do
147
+ ARGV << '--ttl=9'
148
+ @parser.parse
149
+ @parser.instance_variable_get(:@options)[:ttl].should == 9
150
+ end
151
+
152
+ it 'should parse the --reply-to option' do
153
+ ARGV << '--reply-to=/rspec/test'
154
+ @parser.parse
155
+ @parser.instance_variable_get(:@options)[:reply_to].should == '/rspec/test'
156
+ end
157
+
158
+ it 'should parse the --disc-method option' do
159
+ ARGV << '--disc-method=flatfile'
160
+ @parser.parse
161
+ @parser.instance_variable_get(:@options)[:discovery_method].should == 'flatfile'
162
+ end
163
+
164
+ it 'should fail on the --disc-method option if the discovery method has already been set' do
165
+ @parser.instance_variable_get(:@options)[:discovery_method] = 'flatfile'
166
+ ARGV << '--disc-method=dm'
167
+ expect{
168
+ @parser.parse
169
+ }.to raise_error('Discovery method is already set by a competing option')
170
+ end
171
+
172
+ it 'should parse the --publish_timeout option' do
173
+ ARGV << '--publish_timeout=5'
174
+ @parser.parse
175
+ @parser.instance_variable_get(:@options)[:publish_timeout].should == 5
176
+ end
177
+
178
+ it 'should parse the --threaded option' do
179
+ ARGV << '--threaded'
180
+ @parser.parse
181
+ @parser.instance_variable_get(:@options)[:threaded].should == true
182
+ end
183
+
184
+ it 'should parse the --disc-option option' do
185
+ ARGV << '--disc-option=option1'
186
+ ARGV << '--disc-option=option2'
187
+ @parser.parse
188
+ @parser.instance_variable_get(:@options)[:discovery_options].should == ['option1', 'option2']
189
+ ARGV.pop
190
+ end
191
+
192
+ it 'should parse the --nodes option' do
193
+ File.expects(:readable?).with('nodes.txt').returns(true)
194
+ ARGV << '--nodes=nodes.txt'
195
+ @parser.parse
196
+ @parser.instance_variable_get(:@options)[:discovery_method].should == 'flatfile'
197
+ @parser.instance_variable_get(:@options)[:discovery_options].should == ['nodes.txt']
198
+ end
199
+
200
+ it 'should fail on the --nodes option if discovery_method or discovery_options have already been set' do
201
+ end
202
+
203
+ it 'should fail if it cannot read the discovery file' do
204
+ File.expects(:readable?).with('nodes.txt').returns(false)
205
+ ARGV << '--nodes=nodes.txt'
206
+ expect{
207
+ @parser.parse
208
+ }.to raise_error('Cannot read the discovery file nodes.txt')
209
+ end
210
+ end
112
211
  end
113
212
  end
@@ -5,41 +5,70 @@ require 'spec_helper'
5
5
  module MCollective
6
6
  module PluginPackager
7
7
  describe AgentDefinition do
8
+
9
+ let(:configuration) do
10
+ {:target => '.',
11
+ :pluginname => 'test-package',
12
+ :revision => nil,
13
+ :preinstall => nil,
14
+ :postinstall => nil,
15
+ :version => nil,
16
+ :mcname => nil,
17
+ :mcversion => nil,
18
+ :vendor => nil,
19
+ }
20
+ end
21
+
8
22
  before :each do
9
23
  PluginPackager.expects(:get_metadata).once.returns({:name => "foo", :version => 1})
10
24
  end
11
25
 
12
26
  describe "#initialize" do
13
-
14
27
  before do
15
28
  AgentDefinition.any_instance.expects(:common)
16
29
  end
17
30
 
18
31
  it "should replace spaces in the package name with dashes" do
19
- agent = AgentDefinition.new(".", "test package", nil, nil, nil, nil, [], {}, "agent")
32
+ configuration[:pluginname] = 'test-package'
33
+ agent = AgentDefinition.new(configuration, {}, "agent")
20
34
  agent.metadata[:name].should == "test-package"
21
35
  end
22
36
 
37
+ it "should set the version if passed from the config hash" do
38
+ configuration[:version] = '1.2.3'
39
+ agent = AgentDefinition.new(configuration, {}, "agent")
40
+ agent.metadata[:version].should == '1.2.3'
41
+ end
42
+
23
43
  it "should set dependencies if present" do
24
- agent = AgentDefinition.new(".", "test-package", nil, nil, nil, nil, [:name => "foo", :version => nil], {}, "agent")
44
+ configuration[:dependency] = [:name => "foo", :version => nil]
45
+ agent = AgentDefinition.new(configuration, {}, "agent")
25
46
  agent.dependencies.should == [{:name => "foo", :version => nil}, {:name => "mcollective-common", :version => nil}]
26
47
  end
27
48
 
28
49
  it "should set mc name and version" do
29
- agent = AgentDefinition.new(".", "test-package", nil, nil, nil, nil, [], {:mcname =>"pe-mcollective-common", :mcversion =>"1.2"}, "agent")
50
+ agent = AgentDefinition.new(configuration, {:mcname =>"pe-mcollective-common", :mcversion =>"1.2"}, "agent")
30
51
  agent.mcname.should == "pe-mcollective-common"
31
52
  agent.mcversion.should == "1.2"
32
53
  end
33
54
 
34
55
  it "should replace underscored with dashes in the name" do
35
- agent = AgentDefinition.new(".", "test_package", nil, nil, nil, nil, [], {:mcname =>"pe-mcollective-common", :mcversion =>"1.2"}, "agent")
56
+ configuration[:pluginname] = 'test_package'
57
+ agent = AgentDefinition.new(configuration, {}, "agent")
36
58
  agent.metadata[:name].should == "test-package"
37
59
  end
38
60
 
39
61
  it "should replace whitespaces with a single dash in the name" do
40
- agent = AgentDefinition.new(".", "test package", nil, nil, nil, nil, [], {:mcname =>"pe-mcollective-common", :mcversion =>"1.2"}, "agent")
62
+ configuration[:pluginname] = 'test package'
63
+ agent = AgentDefinition.new(configuration, {}, "agent")
41
64
  agent.metadata[:name].should == "test-package"
42
65
  end
66
+
67
+ it 'should set the correct vendor name' do
68
+ configuration[:vendor] = 'rspec'
69
+ agent = AgentDefinition.new(configuration, {}, "agent")
70
+ agent.vendor.should == 'rspec'
71
+ end
43
72
  end
44
73
 
45
74
  describe "#identify_packages" do
@@ -48,7 +77,7 @@ module MCollective
48
77
  AgentDefinition.any_instance.expects(:agent).once.returns(:check)
49
78
  AgentDefinition.any_instance.expects(:client).once.returns(:check)
50
79
 
51
- agent = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
80
+ agent = AgentDefinition.new(configuration, {}, "agent")
52
81
  agent.packagedata[:common].should == :check
53
82
  agent.packagedata[:agent].should == :check
54
83
  agent.packagedata[:client].should == :check
@@ -63,7 +92,7 @@ module MCollective
63
92
  it "should not populate the agent files if the agent directory is empty" do
64
93
  AgentDefinition.any_instance.expects(:common).returns(nil)
65
94
  PluginPackager.expects(:check_dir_present).returns(false)
66
- agent = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
95
+ agent = AgentDefinition.new(configuration, {}, "agent")
67
96
  agent.packagedata[:agent].should == nil
68
97
  end
69
98
 
@@ -76,7 +105,7 @@ module MCollective
76
105
  Dir.stubs(:glob).with("tmpdir/agent/*.ddl").returns([])
77
106
  Dir.stubs(:glob).with("tmpdir/agent/*").returns(["implementation.rb"])
78
107
 
79
- agent = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
108
+ agent = AgentDefinition.new(configuration, {}, "agent")
80
109
  agent.packagedata[:agent][:files].should == ["implementation.rb"]
81
110
  end
82
111
 
@@ -88,9 +117,10 @@ module MCollective
88
117
  File.stubs(:join).with(".", "aggregate").returns("tmpdir/aggregate")
89
118
  Dir.stubs(:glob).returns([])
90
119
 
91
- agent = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
120
+ configuration[:pluginname] = 'foo'
121
+ agent = AgentDefinition.new(configuration, {}, "agent")
92
122
  agent.packagedata[:agent][:dependencies].should == [{:name => "mcollective-common", :version => nil}]
93
- agent.packagedata[:agent][:plugindependency].should == {:name => "mcollective-foo-common", :version =>1, :iteration => 1}
123
+ agent.packagedata[:agent][:plugindependency].should == {:name => "mcollective-foo-common", :version =>1, :revision => 1}
94
124
  end
95
125
  end
96
126
 
@@ -107,7 +137,7 @@ module MCollective
107
137
  Dir.expects(:glob).with("validatordir").returns(["validator.rb"])
108
138
  Dir.expects(:glob).with("ddldir").returns(["agent.ddl"])
109
139
 
110
- common = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
140
+ common = AgentDefinition.new(configuration, {}, "agent")
111
141
  common.packagedata[:common][:files].should == ["data.rb", "util.rb", "validator.rb", "agent.ddl"]
112
142
  end
113
143
 
@@ -123,7 +153,7 @@ module MCollective
123
153
  Dir.expects(:glob).with("ddldir").returns([])
124
154
 
125
155
  expect{
126
- common = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
156
+ common = AgentDefinition.new(configuration, {}, "agent")
127
157
  }.to raise_error(RuntimeError, "cannot create package - No ddl file found in ddldir")
128
158
  end
129
159
  end
@@ -143,7 +173,7 @@ module MCollective
143
173
  Dir.expects(:glob).with("clientdir/*").returns(["client.rb"])
144
174
  Dir.expects(:glob).with("aggregatedir/*").returns(["aggregate.rb"])
145
175
 
146
- client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
176
+ client = AgentDefinition.new(configuration, {}, "agent")
147
177
  client.packagedata[:client][:files].should == ["client.rb", "aggregate.rb"]
148
178
  end
149
179
 
@@ -151,7 +181,7 @@ module MCollective
151
181
  AgentDefinition.any_instance.expects(:common).returns(nil)
152
182
  PluginPackager.expects(:check_dir_present).times(2).returns(false)
153
183
 
154
- client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
184
+ client = AgentDefinition.new(configuration, {}, "agent")
155
185
  client.packagedata[:client].should == nil
156
186
  end
157
187
 
@@ -162,10 +192,11 @@ module MCollective
162
192
  File.expects(:join).with("aggregatedir", "*").returns("aggregatedir/*")
163
193
  Dir.expects(:glob).with("clientdir/*").returns(["client.rb"])
164
194
  Dir.expects(:glob).with("aggregatedir/*").returns(["aggregate.rb"])
195
+ configuration[:pluginname] = 'foo'
165
196
 
166
- client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
197
+ client = AgentDefinition.new(configuration, {}, "agent")
167
198
  client.packagedata[:client][:dependencies].should == [{:name => "mcollective-common", :version => nil}]
168
- client.packagedata[:client][:plugindependency].should == {:name => "mcollective-foo-common", :version => 1, :iteration => 1}
199
+ client.packagedata[:client][:plugindependency].should == {:name => "mcollective-foo-common", :version => 1, :revision => 1}
169
200
  end
170
201
  end
171
202
  end
@@ -5,36 +5,59 @@ require 'spec_helper'
5
5
  module MCollective
6
6
  module PluginPackager
7
7
  describe StandardDefinition do
8
+
9
+ let(:configuration) do
10
+ {:target => '.',
11
+ :pluginname => 'test-package',
12
+ :revision => nil,
13
+ :preinstall => nil,
14
+ :postinstall => nil,
15
+ :version => nil,
16
+ :mcname => nil,
17
+ :mcversion => nil
18
+ }
19
+ end
20
+
8
21
  before :each do
9
22
  PluginPackager.expects(:get_metadata).once.returns({:name => "foo", :version => 1})
10
23
  end
11
24
 
12
25
  describe "#initialize" do
13
- it "should replace spaces in the package name with dashes" do
14
- plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {}, "testplugin")
26
+ it "should replace whitespaces in the package name with dashes" do
27
+ configuration[:pluginname] = 'test plugin'
28
+ plugin = StandardDefinition.new(configuration, {}, "testplugin")
15
29
  plugin.metadata[:name].should == "test-plugin"
16
30
  end
17
31
 
32
+ it "should set the version if passed from the config hash" do
33
+ configuration[:version] = '1.2.3'
34
+ plugin = StandardDefinition.new(configuration, {}, "testplugin")
35
+ plugin.metadata[:version].should == '1.2.3'
36
+ end
37
+
18
38
  it "should set dependencies if present" do
19
- plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [{:name => "foo", :version => nil}], {}, "testplugin")
39
+ configuration[:dependency] = [{:name => "foo", :version => nil}]
40
+ plugin = StandardDefinition.new(configuration, {}, "testplugin")
20
41
  plugin.dependencies.should == [{:name => "foo", :version => nil},
21
42
  {:name => "mcollective-common", :version => nil}]
22
43
  end
23
44
 
24
45
  it "should set mc name and version dependencies" do
25
- plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin")
46
+ plugin = StandardDefinition.new(configuration, {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin")
26
47
  plugin.mcname.should == "pe-mcollective"
27
48
  plugin.mcversion.should == "1"
28
49
  end
29
50
 
30
51
  it "should replace underscores with dashes in the name" do
31
- plugin = StandardDefinition.new(".", "test_plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin")
52
+ configuration[:pluginname] = 'test_plugin'
53
+ plugin = StandardDefinition.new(configuration, {}, "testplugin")
32
54
  plugin.metadata[:name].should == "test-plugin"
33
55
  end
34
56
 
35
- it "should replace whitespaces with a single dash in the name" do
36
- plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin")
37
- plugin.metadata[:name].should == "test-plugin"
57
+ it 'should set the correct vendor name' do
58
+ configuration[:vendor] = 'rspec'
59
+ agent = StandardDefinition.new(configuration, {}, "agent")
60
+ agent.vendor.should == 'rspec'
38
61
  end
39
62
  end
40
63
 
@@ -43,9 +66,9 @@ module MCollective
43
66
  StandardDefinition.any_instance.expects(:common).once.returns(:check)
44
67
  StandardDefinition.any_instance.expects(:plugin).once.returns(:check)
45
68
 
46
- plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
69
+ plugin = StandardDefinition.new(configuration, {}, "testplugin")
47
70
  plugin.packagedata[:common].should == :check
48
- plugin.packagedata["testplugin"].should == :check
71
+ plugin.packagedata[:testplugin].should == :check
49
72
  end
50
73
  end
51
74
 
@@ -54,26 +77,27 @@ module MCollective
54
77
  it "should return nil if the plugin doesn't contain any files" do
55
78
  StandardDefinition.any_instance.expects(:common).returns(nil)
56
79
  PluginPackager.expects(:check_dir_present).returns(false)
57
- plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
58
- plugin.packagedata["testplugin"].should == nil
80
+ plugin = StandardDefinition.new(configuration, {}, "testplugin")
81
+ plugin.packagedata[:testplugin].should == nil
59
82
  end
60
83
 
61
84
  it "should add plugin files to the file list" do
62
85
  StandardDefinition.any_instance.expects(:common).returns(nil)
63
86
  PluginPackager.expects(:check_dir_present).returns(true)
64
87
  Dir.expects(:glob).with("./testplugin/*").returns(["file.rb"])
65
- plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
66
- plugin.packagedata["testplugin"][:files].should == ["file.rb"]
88
+ plugin = StandardDefinition.new(configuration, {}, "testplugin")
89
+ plugin.packagedata[:testplugin][:files].should == ["file.rb"]
67
90
  end
68
91
 
69
92
  it "should add common package as dependency if present" do
93
+ configuration[:pluginname] = 'foo'
70
94
  StandardDefinition.any_instance.expects(:common).returns(true)
71
95
  PluginPackager.expects(:check_dir_present).returns(true)
72
96
  Dir.expects(:glob).with("./testplugin/*").returns(["file.rb"])
73
- plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
74
- plugin.packagedata["testplugin"][:files].should == ["file.rb"]
75
- plugin.packagedata["testplugin"][:dependencies].should == [{:name => "mcollective-common", :version => nil}]
76
- plugin.packagedata["testplugin"][:plugindependency].should == {:name => "mcollective-foo-common", :version => 1, :iteration => 1}
97
+ plugin = StandardDefinition.new(configuration, {}, "testplugin")
98
+ plugin.packagedata[:testplugin][:files].should == ["file.rb"]
99
+ plugin.packagedata[:testplugin][:dependencies].should == [{:name => "mcollective-common", :version => nil}]
100
+ plugin.packagedata[:testplugin][:plugindependency].should == {:name => "mcollective-foo-common", :version => 1, :revision => 1}
77
101
  end
78
102
  end
79
103
 
@@ -84,14 +108,14 @@ module MCollective
84
108
 
85
109
  it "should return nil if common doesn't contain any files" do
86
110
  PluginPackager.expects(:check_dir_present).returns(false)
87
- plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
111
+ plugin = StandardDefinition.new(configuration, {}, "testplugin")
88
112
  plugin.packagedata[:common].should == nil
89
113
  end
90
114
 
91
115
  it "should add common files to the file list" do
92
116
  PluginPackager.expects(:check_dir_present).returns(true)
93
117
  Dir.expects(:glob).with("./util/*").returns(["common.rb"])
94
- plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
118
+ plugin = StandardDefinition.new(configuration, {}, "testplugin")
95
119
  plugin.packagedata[:common][:files].should == ["common.rb"]
96
120
  end
97
121
  end
@@ -75,16 +75,16 @@ module MCollective
75
75
  end
76
76
  end
77
77
 
78
- describe "#do_quietly?" do
78
+ describe "#execute_verbosely" do
79
79
  it "should call the block parameter if verbose is true" do
80
- result = PluginPackager.do_quietly?(true) {:success}
80
+ result = PluginPackager.execute_verbosely(true) {:success}
81
81
  result.should == :success
82
82
  end
83
83
 
84
84
  it "should call the block parameter quietly if verbose is false" do
85
85
  std_out = Tempfile.new("mc_pluginpackager_spec")
86
86
  File.expects(:new).with("/dev/null", "w").returns(std_out)
87
- PluginPackager.do_quietly?(false) {puts "success"}
87
+ PluginPackager.execute_verbosely(false) {puts "success"}
88
88
  std_out.rewind
89
89
  std_out.read.should == "success\n"
90
90
  std_out.close
@@ -93,23 +93,23 @@ module MCollective
93
93
 
94
94
  it "should raise an exception and reset stdout if the block raises an execption" do
95
95
  expect{
96
- PluginPackager.do_quietly?(false) {raise Exception, "exception"}
96
+ PluginPackager.execute_verbosely(false) {raise Exception, "exception"}
97
97
  }.to raise_error(Exception, "exception")
98
98
  end
99
99
  end
100
100
 
101
- describe "#build_tool?" do
101
+ describe "#command_available?" do
102
102
  it "should return true if the given build tool is present on the system" do
103
103
  File.expects(:join).returns("foo")
104
104
  File.expects(:exists?).with("foo").returns(true)
105
- result = PluginPackager.build_tool?("foo")
105
+ result = PluginPackager.command_available?("foo")
106
106
  result.should == true
107
107
  end
108
108
 
109
109
  it "should return false if the given build tool is not present on the system" do
110
110
  File.stubs(:join).returns("foo")
111
111
  File.stubs(:exists?).with("foo").returns(false)
112
- result = PluginPackager.build_tool?("foo")
112
+ result = PluginPackager.command_available?("foo")
113
113
  result.should == false
114
114
  end
115
115
  end
@@ -127,5 +127,29 @@ module MCollective
127
127
  }.to raise_error(RuntimeError, "Failed: foo")
128
128
  end
129
129
  end
130
+
131
+ describe '#filter_dependencies' do
132
+ before :each do
133
+ @dependencies = [{:name => 'rspec', :version => '1.0'}]
134
+ end
135
+
136
+ it 'should leave normal dependencies intact' do
137
+ result = PluginPackager.filter_dependencies('debian', @dependencies)
138
+ result.should == @dependencies
139
+ end
140
+
141
+ it 'should filter out dependencies with the incorrect prefix' do
142
+ @dependencies << {:name => 'redhat::rspec_redhat', :version => '2.0'}
143
+ result = PluginPackager.filter_dependencies('debian', @dependencies)
144
+ result.should == [{:name => 'rspec', :version => '1.0'}]
145
+ end
146
+
147
+ it 'should reformat dependencies with the correct prefix' do
148
+ @dependencies << {:name => 'debian::rspec_debian', :version => '2.0'}
149
+ result = PluginPackager.filter_dependencies('debian', @dependencies)
150
+ result.should == [{:name => 'rspec', :version => '1.0'},
151
+ {:name => 'rspec_debian', :version => '2.0'}]
152
+ end
153
+ end
130
154
  end
131
155
  end