mcollective-client 1.3.3

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 (103) hide show
  1. data/bin/mc-call-agent +54 -0
  2. data/bin/mco +27 -0
  3. data/lib/mcollective.rb +70 -0
  4. data/lib/mcollective/agents.rb +160 -0
  5. data/lib/mcollective/application.rb +354 -0
  6. data/lib/mcollective/applications.rb +145 -0
  7. data/lib/mcollective/client.rb +292 -0
  8. data/lib/mcollective/config.rb +202 -0
  9. data/lib/mcollective/connector.rb +18 -0
  10. data/lib/mcollective/connector/base.rb +24 -0
  11. data/lib/mcollective/facts.rb +39 -0
  12. data/lib/mcollective/facts/base.rb +86 -0
  13. data/lib/mcollective/log.rb +103 -0
  14. data/lib/mcollective/logger.rb +5 -0
  15. data/lib/mcollective/logger/base.rb +73 -0
  16. data/lib/mcollective/logger/console_logger.rb +61 -0
  17. data/lib/mcollective/logger/file_logger.rb +46 -0
  18. data/lib/mcollective/logger/syslog_logger.rb +53 -0
  19. data/lib/mcollective/matcher.rb +16 -0
  20. data/lib/mcollective/matcher/parser.rb +93 -0
  21. data/lib/mcollective/matcher/scanner.rb +123 -0
  22. data/lib/mcollective/message.rb +201 -0
  23. data/lib/mcollective/monkey_patches.rb +104 -0
  24. data/lib/mcollective/optionparser.rb +164 -0
  25. data/lib/mcollective/pluginmanager.rb +180 -0
  26. data/lib/mcollective/pluginpackager.rb +26 -0
  27. data/lib/mcollective/pluginpackager/agent_definition.rb +79 -0
  28. data/lib/mcollective/pluginpackager/standard_definition.rb +59 -0
  29. data/lib/mcollective/registration.rb +16 -0
  30. data/lib/mcollective/registration/base.rb +75 -0
  31. data/lib/mcollective/rpc.rb +188 -0
  32. data/lib/mcollective/rpc/actionrunner.rb +142 -0
  33. data/lib/mcollective/rpc/agent.rb +441 -0
  34. data/lib/mcollective/rpc/audit.rb +38 -0
  35. data/lib/mcollective/rpc/client.rb +793 -0
  36. data/lib/mcollective/rpc/ddl.rb +258 -0
  37. data/lib/mcollective/rpc/helpers.rb +339 -0
  38. data/lib/mcollective/rpc/progress.rb +63 -0
  39. data/lib/mcollective/rpc/reply.rb +61 -0
  40. data/lib/mcollective/rpc/request.rb +51 -0
  41. data/lib/mcollective/rpc/result.rb +41 -0
  42. data/lib/mcollective/rpc/stats.rb +185 -0
  43. data/lib/mcollective/runnerstats.rb +90 -0
  44. data/lib/mcollective/security.rb +26 -0
  45. data/lib/mcollective/security/base.rb +237 -0
  46. data/lib/mcollective/shell.rb +87 -0
  47. data/lib/mcollective/ssl.rb +246 -0
  48. data/lib/mcollective/unix_daemon.rb +37 -0
  49. data/lib/mcollective/util.rb +274 -0
  50. data/lib/mcollective/vendor.rb +41 -0
  51. data/lib/mcollective/vendor/require_vendored.rb +2 -0
  52. data/lib/mcollective/windows_daemon.rb +25 -0
  53. data/spec/Rakefile +16 -0
  54. data/spec/fixtures/application/test.rb +7 -0
  55. data/spec/fixtures/test-cert.pem +15 -0
  56. data/spec/fixtures/test-private.pem +15 -0
  57. data/spec/fixtures/test-public.pem +6 -0
  58. data/spec/monkey_patches/instance_variable_defined.rb +7 -0
  59. data/spec/spec.opts +1 -0
  60. data/spec/spec_helper.rb +25 -0
  61. data/spec/unit/agents_spec.rb +280 -0
  62. data/spec/unit/application_spec.rb +636 -0
  63. data/spec/unit/applications_spec.rb +155 -0
  64. data/spec/unit/array.rb +30 -0
  65. data/spec/unit/config_spec.rb +148 -0
  66. data/spec/unit/facts/base_spec.rb +118 -0
  67. data/spec/unit/facts_spec.rb +39 -0
  68. data/spec/unit/log_spec.rb +71 -0
  69. data/spec/unit/logger/base_spec.rb +110 -0
  70. data/spec/unit/logger/syslog_logger_spec.rb +86 -0
  71. data/spec/unit/matcher/parser_spec.rb +106 -0
  72. data/spec/unit/matcher/scanner_spec.rb +71 -0
  73. data/spec/unit/message_spec.rb +401 -0
  74. data/spec/unit/optionparser_spec.rb +113 -0
  75. data/spec/unit/pluginmanager_spec.rb +173 -0
  76. data/spec/unit/pluginpackager/agent_definition_spec.rb +130 -0
  77. data/spec/unit/pluginpackager/standard_definition_spec.rb +75 -0
  78. data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +533 -0
  79. data/spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb +34 -0
  80. data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +417 -0
  81. data/spec/unit/plugins/mcollective/packagers/ospackage_spec.rb +229 -0
  82. data/spec/unit/plugins/mcollective/security/psk_spec.rb +156 -0
  83. data/spec/unit/registration/base_spec.rb +77 -0
  84. data/spec/unit/rpc/actionrunner_spec.rb +213 -0
  85. data/spec/unit/rpc/agent_spec.rb +155 -0
  86. data/spec/unit/rpc/client_spec.rb +523 -0
  87. data/spec/unit/rpc/ddl_spec.rb +388 -0
  88. data/spec/unit/rpc/helpers_spec.rb +55 -0
  89. data/spec/unit/rpc/reply_spec.rb +143 -0
  90. data/spec/unit/rpc/request_spec.rb +115 -0
  91. data/spec/unit/rpc/result_spec.rb +66 -0
  92. data/spec/unit/rpc/stats_spec.rb +288 -0
  93. data/spec/unit/runnerstats_spec.rb +40 -0
  94. data/spec/unit/security/base_spec.rb +279 -0
  95. data/spec/unit/shell_spec.rb +144 -0
  96. data/spec/unit/ssl_spec.rb +244 -0
  97. data/spec/unit/symbol.rb +11 -0
  98. data/spec/unit/unix_daemon.rb +41 -0
  99. data/spec/unit/util_spec.rb +342 -0
  100. data/spec/unit/vendor_spec.rb +34 -0
  101. data/spec/unit/windows_daemon.rb +43 -0
  102. data/spec/windows_spec.opts +1 -0
  103. metadata +242 -0
@@ -0,0 +1,388 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ module RPC
7
+ describe DDL do
8
+ before :each do
9
+ @ddl = DDL.new("rspec", false)
10
+ end
11
+
12
+ describe "#findddlfile" do
13
+ it "should construct the correct ddl file name" do
14
+ Config.any_instance.expects(:libdir).returns(["/nonexisting"])
15
+ File.expects("exist?").with("/nonexisting/mcollective/agent/foo.ddl").returns(false)
16
+
17
+ @ddl.findddlfile("foo").should == false
18
+ end
19
+
20
+ it "should check each libdir for a ddl file" do
21
+ Config.any_instance.expects(:libdir).returns(["/nonexisting1", "/nonexisting2"])
22
+ File.expects("exist?").with("/nonexisting1/mcollective/agent/foo.ddl").returns(false)
23
+ File.expects("exist?").with("/nonexisting2/mcollective/agent/foo.ddl").returns(false)
24
+
25
+ @ddl.findddlfile("foo").should == false
26
+ end
27
+
28
+ it "should return the ddl file path if found" do
29
+ Config.any_instance.expects(:libdir).returns(["/nonexisting"])
30
+ File.expects("exist?").with("/nonexisting/mcollective/agent/foo.ddl").returns(true)
31
+ Log.expects(:debug).with("Found foo ddl at /nonexisting/mcollective/agent/foo.ddl")
32
+
33
+ @ddl.findddlfile("foo").should == "/nonexisting/mcollective/agent/foo.ddl"
34
+ end
35
+ end
36
+
37
+ describe "#metadata" do
38
+ it "should ensure minimum parameters are given" do
39
+ [:name, :description, :author, :license, :version, :url, :timeout].each do |tst|
40
+ metadata = {:name => "name", :description => "description", :author => "author",
41
+ :license => "license", :version => "version", :url => "url", :timeout => "timeout"}
42
+
43
+ metadata.delete(tst)
44
+
45
+ expect {
46
+ @ddl.metadata(metadata)
47
+ }.to raise_error("Metadata needs a :#{tst}")
48
+ end
49
+ end
50
+
51
+ it "should should allow arbitrary metadata" do
52
+ metadata = {:name => "name", :description => "description", :author => "author", :license => "license",
53
+ :version => "version", :url => "url", :timeout => "timeout", :foo => "bar"}
54
+
55
+ @ddl.metadata(metadata)
56
+ @ddl.meta.should == metadata
57
+ end
58
+ end
59
+
60
+ describe "#action" do
61
+ it "should ensure a description is set" do
62
+ expect {
63
+ @ddl.action("act", {})
64
+ }.to raise_error("Action needs a :description")
65
+ end
66
+
67
+ it "should create a default action structure" do
68
+ @ddl.action("act", :description => "rspec")
69
+
70
+ action = @ddl.action_interface("act")
71
+
72
+ action.class.should == Hash
73
+ action[:action].should == "act"
74
+ action[:input].should == {}
75
+ action[:output].should == {}
76
+ action[:display].should == :failed
77
+ action[:description].should == "rspec"
78
+ end
79
+
80
+ it "should call a block if one is given and set the correct action name" do
81
+ @ddl.action("act", :description => "rspec") { @ddl.instance_variable_get("@current_action").should == "act" }
82
+ end
83
+ end
84
+
85
+ describe "#input" do
86
+ it "should ensure required properties are set" do
87
+ @ddl.action(:test, :description => "rspec")
88
+ @ddl.instance_variable_set("@current_action", :test)
89
+
90
+ [:prompt, :description, :type, :optional].each do |arg|
91
+ args = {:prompt => "prompt", :description => "descr", :type => "type", :optional => true}
92
+ args.delete(arg)
93
+
94
+ expect {
95
+ @ddl.input(:test, args)
96
+ }.to raise_error("Input needs a :#{arg}")
97
+ end
98
+
99
+ @ddl.input(:test, {:prompt => "prompt", :description => "descr", :type => "type", :optional => true})
100
+ end
101
+
102
+ it "should ensure strings have a validation and maxlength" do
103
+ @ddl.action(:test, :description => "rspec")
104
+ @ddl.instance_variable_set("@current_action", :test)
105
+
106
+ expect {
107
+ @ddl.input(:test, :prompt => "prompt", :description => "descr",
108
+ :type => :string, :optional => true)
109
+ }.to raise_error("Input type :string needs a :validation argument")
110
+
111
+ expect {
112
+ @ddl.input(:test, :prompt => "prompt", :description => "descr",
113
+ :type => :string, :optional => true, :validation => 1)
114
+ }.to raise_error("Input type :string needs a :maxlength argument")
115
+
116
+ @ddl.input(:test, :prompt => "prompt", :description => "descr",
117
+ :type => :string, :optional => true, :validation => 1, :maxlength => 1)
118
+ end
119
+
120
+ it "should ensure lists have a list argument" do
121
+ @ddl.action(:test, :description => "rspec")
122
+ @ddl.instance_variable_set("@current_action", :test)
123
+
124
+ expect {
125
+ @ddl.input(:test, :prompt => "prompt", :description => "descr",
126
+ :type => :list, :optional => true)
127
+ }.to raise_error("Input type :list needs a :list argument")
128
+
129
+ @ddl.input(:test, :prompt => "prompt", :description => "descr",
130
+ :type => :list, :optional => true, :list => [])
131
+ end
132
+
133
+ it "should save correct data for a list input" do
134
+ @ddl.action(:test, :description => "rspec")
135
+ @ddl.instance_variable_set("@current_action", :test)
136
+ @ddl.input(:test, :prompt => "prompt", :description => "descr",
137
+ :type => :list, :optional => true, :list => [])
138
+
139
+ action = @ddl.action_interface(:test)
140
+
141
+ action[:input][:test][:prompt].should == "prompt"
142
+ action[:input][:test][:description].should == "descr"
143
+ action[:input][:test][:type].should == :list
144
+ action[:input][:test][:optional].should == true
145
+ action[:input][:test][:list].should == []
146
+ end
147
+
148
+ it "should save correct data for a string input" do
149
+ @ddl.action(:test, :description => "rspec")
150
+ @ddl.instance_variable_set("@current_action", :test)
151
+ @ddl.input(:test, :prompt => "prompt", :description => "descr",
152
+ :type => :string, :optional => true, :validation => "",
153
+ :maxlength => 1)
154
+
155
+ action = @ddl.action_interface(:test)
156
+
157
+ action[:input][:test][:prompt].should == "prompt"
158
+ action[:input][:test][:description].should == "descr"
159
+ action[:input][:test][:type].should == :string
160
+ action[:input][:test][:optional].should == true
161
+ action[:input][:test][:validation].should == ""
162
+ action[:input][:test][:maxlength].should == 1
163
+ end
164
+ end
165
+
166
+ describe "#output" do
167
+ it "should ensure a :description is set" do
168
+ @ddl.action(:test, :description => "rspec")
169
+ @ddl.instance_variable_set("@current_action", :test)
170
+
171
+ expect {
172
+ @ddl.output(:test, {})
173
+ }.to raise_error("Output test needs a description argument")
174
+ end
175
+
176
+ it "should ensure a :display_as is set" do
177
+ @ddl.action(:test, :description => "rspec")
178
+ @ddl.instance_variable_set("@current_action", :test)
179
+
180
+ expect {
181
+ @ddl.output(:test, {:description => "rspec"})
182
+ }.to raise_error("Output test needs a display_as argument")
183
+ end
184
+
185
+ it "should save correct data for an output" do
186
+ @ddl.action(:test, :description => "rspec")
187
+ @ddl.instance_variable_set("@current_action", :test)
188
+
189
+ @ddl.output(:test, {:description => "rspec", :display_as => "RSpec"})
190
+
191
+ action = @ddl.action_interface(:test)
192
+
193
+ action[:output][:test][:description].should == "rspec"
194
+ action[:output][:test][:display_as].should == "RSpec"
195
+ end
196
+ end
197
+
198
+ describe "#display" do
199
+ it "should ensure a valid display property is set" do
200
+ @ddl.action(:test, :description => "rspec")
201
+ @ddl.instance_variable_set("@current_action", :test)
202
+
203
+ [:ok, :failed, :flatten, :always].each do |display|
204
+ @ddl.display(display)
205
+
206
+ action = @ddl.action_interface(:test)
207
+ action[:display].should == display
208
+ end
209
+
210
+ expect {
211
+ @ddl.display(:foo)
212
+ }.to raise_error("Display preference foo is not valid, should be :ok, :failed, :flatten or :always")
213
+ end
214
+ end
215
+
216
+ describe "#help" do
217
+ it "should correctly execute the template with a valid binding" do
218
+ @ddl.instance_variable_set("@meta", "meta")
219
+ @ddl.instance_variable_set("@actions", "actions")
220
+ IO.expects(:read).with("/template").returns("<%= meta %>:<%= actions %>")
221
+ @ddl.help("/template").should == "meta:actions"
222
+ end
223
+ end
224
+
225
+ describe "#actions" do
226
+ it "should return the correct list of actions" do
227
+ @ddl.action(:test1, :description => "rspec")
228
+ @ddl.action(:test2, :description => "rspec")
229
+
230
+ @ddl.actions.sort.should == [:test1, :test2]
231
+ end
232
+ end
233
+
234
+ describe "#action_interface" do
235
+ it "should return the correct interface" do
236
+ @ddl.action(:test1, :description => "rspec")
237
+ @ddl.action_interface(:test1).should == {:description=>"rspec", :output=>{}, :input=>{}, :action=>:test1, :display=>:failed}
238
+ end
239
+ end
240
+
241
+ describe "#validate_request" do
242
+ it "should ensure the action is known" do
243
+ @ddl.action(:test, :description => "rspec")
244
+
245
+ expect {
246
+ @ddl.validate_request(:fail, {})
247
+ }.to raise_error("Attempted to call action fail for rspec but it's not declared in the DDL")
248
+
249
+ @ddl.validate_request(:test, {})
250
+ end
251
+
252
+ it "should check all required arguments are present" do
253
+ @ddl.action(:test, :description => "rspec")
254
+ @ddl.instance_variable_set("@current_action", :test)
255
+ @ddl.input(:optional, :prompt => "prompt", :description => "descr",
256
+ :type => :string, :optional => true, :validation => "",
257
+ :maxlength => 1)
258
+ @ddl.input(:required, :prompt => "prompt", :description => "descr",
259
+ :type => :string, :optional => false, :validation => "",
260
+ :maxlength => 1)
261
+
262
+ expect {
263
+ @ddl.validate_request(:test, {})
264
+ }.to raise_error("Action test needs a required argument")
265
+
266
+ @ddl.validate_request(:test, {:required => "f"}).should == true
267
+ end
268
+
269
+ it "should ensure strings are String" do
270
+ @ddl.action(:string, :description => "rspec")
271
+ @ddl.instance_variable_set("@current_action", :string)
272
+ @ddl.input(:string, :prompt => "prompt", :description => "descr",
273
+ :type => :string, :optional => true, :validation => "",
274
+ :maxlength => 1)
275
+
276
+ expect {
277
+ @ddl.validate_request(:string, {:string => 1})
278
+ }.to raise_error("Input string should be a string")
279
+
280
+ @ddl.validate_request(:string, {:string => "1"})
281
+ end
282
+
283
+ it "should ensure strings are not longer than maxlength" do
284
+ @ddl.action(:string, :description => "rspec")
285
+ @ddl.instance_variable_set("@current_action", :string)
286
+ @ddl.input(:string, :prompt => "prompt", :description => "descr",
287
+ :type => :string, :optional => true, :validation => "",
288
+ :maxlength => 1)
289
+
290
+ expect {
291
+ @ddl.validate_request(:string, {:string => "too long"})
292
+ }.to raise_error("Input string is longer than 1 character(s)")
293
+
294
+ @ddl.validate_request(:string, {:string => "1"})
295
+ end
296
+
297
+ it "should validate strings using regular expressions" do
298
+ @ddl.action(:string, :description => "rspec")
299
+ @ddl.instance_variable_set("@current_action", :string)
300
+ @ddl.input(:string, :prompt => "prompt", :description => "descr",
301
+ :type => :string, :optional => true, :validation => "^regex$",
302
+ :maxlength => 100)
303
+
304
+ expect {
305
+ @ddl.validate_request(:string, {:string => "doesnt validate"})
306
+ }.to raise_error("Input string does not match validation regex ^regex$")
307
+
308
+ @ddl.validate_request(:string, {:string => "regex"})
309
+ end
310
+
311
+ it "should validate list arguments correctly" do
312
+ @ddl.action(:list, :description => "rspec")
313
+ @ddl.instance_variable_set("@current_action", :list)
314
+ @ddl.input(:list, :prompt => "prompt", :description => "descr",
315
+ :type => :list, :optional => true, :list => [1,2])
316
+
317
+ expect {
318
+ @ddl.validate_request(:list, {:list => 3})
319
+ }.to raise_error("Input list doesn't match list 1, 2")
320
+
321
+ @ddl.validate_request(:list, {:list => 1})
322
+ end
323
+
324
+ it "should validate boolean arguments correctly" do
325
+ @ddl.action(:bool, :description => "rspec")
326
+ @ddl.instance_variable_set("@current_action", :bool)
327
+ @ddl.input(:bool, :prompt => "prompt", :description => "descr",
328
+ :type => :boolean, :optional => true)
329
+
330
+ expect {
331
+ @ddl.validate_request(:bool, {:bool => 3})
332
+ }.to raise_error("Input bool should be a boolean")
333
+
334
+ @ddl.validate_request(:bool, {:bool => true})
335
+ @ddl.validate_request(:bool, {:bool => false})
336
+ end
337
+
338
+ it "should validate integer arguments correctly" do
339
+ @ddl.action(:test, :description => "rspec")
340
+ @ddl.instance_variable_set("@current_action", :test)
341
+ @ddl.input(:int, :prompt => "prompt", :description => "descr",
342
+ :type => :integer, :optional => true)
343
+
344
+ expect {
345
+ @ddl.validate_request(:test, {:int => "1"})
346
+ }.to raise_error("Input int should be a integer")
347
+
348
+ expect {
349
+ @ddl.validate_request(:test, {:int => 1.1})
350
+ }.to raise_error("Input int should be a integer")
351
+
352
+ @ddl.validate_request(:test, {:int => 1})
353
+ end
354
+
355
+ it "should validate float arguments correctly" do
356
+ @ddl.action(:test, :description => "rspec")
357
+ @ddl.instance_variable_set("@current_action", :test)
358
+ @ddl.input(:float, :prompt => "prompt", :description => "descr",
359
+ :type => :float, :optional => true)
360
+
361
+ expect {
362
+ @ddl.validate_request(:test, {:float => "1"})
363
+ }.to raise_error("Input float should be a floating point number")
364
+
365
+ expect {
366
+ @ddl.validate_request(:test, {:float => 1})
367
+ }.to raise_error("Input float should be a floating point number")
368
+
369
+ @ddl.validate_request(:test, {:float => 1.1})
370
+ end
371
+
372
+ it "should validate number arguments correctly" do
373
+ @ddl.action(:test, :description => "rspec")
374
+ @ddl.instance_variable_set("@current_action", :test)
375
+ @ddl.input(:number, :prompt => "prompt", :description => "descr",
376
+ :type => :number, :optional => true)
377
+
378
+ expect {
379
+ @ddl.validate_request(:test, {:number => "1"})
380
+ }.to raise_error("Input number should be a number")
381
+
382
+ @ddl.validate_request(:test, {:number => 1})
383
+ @ddl.validate_request(:test, {:number => 1.1})
384
+ end
385
+ end
386
+ end
387
+ end
388
+ end
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ module RPC
7
+ describe Helpers do
8
+ describe "#extract_hosts_from_json" do
9
+ it "should fail for non array data" do
10
+ expect {
11
+ Helpers.extract_hosts_from_json("{}")
12
+ }.to raise_error "JSON hosts list is not an array"
13
+ end
14
+
15
+ it "should fail for non hash array members" do
16
+ senders = [{"sender" => "sender1"}, {"sender" => "sender3"}, ""].to_json
17
+
18
+ expect {
19
+ Helpers.extract_hosts_from_json(senders)
20
+ }.to raise_error "JSON host list is not an array of Hashes"
21
+ end
22
+
23
+ it "should fail for hashes without senders" do
24
+ senders = [{"sender" => "sender1"}, {"sender" => "sender3"}, {}].to_json
25
+
26
+ expect {
27
+ Helpers.extract_hosts_from_json(senders)
28
+ }.to raise_error "JSON host list does not have senders in it"
29
+ end
30
+
31
+ it "should return all found unique senders" do
32
+ senders = [{"sender" => "sender1"}, {"sender" => "sender3"}, {"sender" => "sender1"}].to_json
33
+
34
+ Helpers.extract_hosts_from_json(senders).should == ["sender1", "sender3"]
35
+ end
36
+ end
37
+
38
+ describe "#extract_hosts_from_array" do
39
+ it "should support single string lists" do
40
+ Helpers.extract_hosts_from_array("foo").should == ["foo"]
41
+ end
42
+
43
+ it "should support arrays" do
44
+ Helpers.extract_hosts_from_array(["foo", "bar"]).should == ["foo", "bar"]
45
+ end
46
+
47
+ it "should fail for non string array members" do
48
+ expect {
49
+ Helpers.extract_hosts_from_array(["foo", 1])
50
+ }.to raise_error("1 should be a string")
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ module RPC
7
+ describe Reply do
8
+ before(:each) do
9
+ @reply = Reply.new
10
+ end
11
+
12
+ describe "#initialize" do
13
+ it "should set an empty data hash" do
14
+ @reply.data.should == {}
15
+ end
16
+
17
+ it "should set statuscode to zero" do
18
+ @reply.statuscode.should == 0
19
+ end
20
+
21
+ it "should set statusmsg to OK" do
22
+ @reply.statusmsg.should == "OK"
23
+ end
24
+ end
25
+
26
+ describe "#fail" do
27
+ it "should set statusmsg" do
28
+ @reply.fail "foo"
29
+ @reply.statusmsg.should == "foo"
30
+ end
31
+
32
+ it "should set statuscode to 1 by default" do
33
+ @reply.fail("foo")
34
+ @reply.statuscode.should == 1
35
+ end
36
+
37
+ it "should set statuscode" do
38
+ @reply.fail("foo", 2)
39
+ @reply.statuscode.should == 2
40
+ end
41
+ end
42
+
43
+ describe "#fail!" do
44
+ it "should set statusmsg" do
45
+ expect {
46
+ @reply.fail! "foo"
47
+ }.to raise_error(RPCAborted, "foo")
48
+
49
+ @reply.statusmsg.should == "foo"
50
+ end
51
+
52
+ it "should set statuscode to 1 by default" do
53
+ expect {
54
+ @reply.fail! "foo"
55
+ }.to raise_error(RPCAborted)
56
+ end
57
+
58
+ it "should set statuscode" do
59
+ expect {
60
+ @reply.fail! "foo", 2
61
+ }.to raise_error(UnknownRPCAction)
62
+
63
+ @reply.statuscode.should == 2
64
+ end
65
+
66
+ it "should raise RPCAborted for code 1" do
67
+ expect {
68
+ @reply.fail! "foo", 1
69
+ }.to raise_error(RPCAborted)
70
+ end
71
+
72
+ it "should raise UnknownRPCAction for code 2" do
73
+ expect {
74
+ @reply.fail! "foo", 2
75
+ }.to raise_error(UnknownRPCAction)
76
+ end
77
+
78
+ it "should raise MissingRPCData for code 3" do
79
+ expect {
80
+ @reply.fail! "foo", 3
81
+ }.to raise_error(MissingRPCData)
82
+ end
83
+
84
+ it "should raise InvalidRPCData for code 4" do
85
+ expect {
86
+ @reply.fail! "foo", 4
87
+ }.to raise_error(InvalidRPCData)
88
+ end
89
+
90
+ it "should raise UnknownRPCError for all other codes" do
91
+ expect {
92
+ @reply.fail! "foo", 5
93
+ }.to raise_error(UnknownRPCError)
94
+
95
+ expect {
96
+ @reply.fail! "foo", "x"
97
+ }.to raise_error(UnknownRPCError)
98
+ end
99
+ end
100
+
101
+ describe "#[]=" do
102
+ it "should save the correct data to the data hash" do
103
+ @reply[:foo] = "foo1"
104
+ @reply["foo"] = "foo2"
105
+
106
+ @reply.data[:foo].should == "foo1"
107
+ @reply.data["foo"].should == "foo2"
108
+ end
109
+ end
110
+
111
+ describe "#[]" do
112
+ it "should return the correct saved data" do
113
+ @reply[:foo] = "foo1"
114
+ @reply["foo"] = "foo2"
115
+
116
+ @reply[:foo].should == "foo1"
117
+ @reply["foo"].should == "foo2"
118
+ end
119
+ end
120
+
121
+ describe "#to_hash" do
122
+ it "should have the correct keys" do
123
+ @reply.to_hash.keys.sort.should == [:data, :statuscode, :statusmsg]
124
+ end
125
+
126
+ it "should have the correct statuscode" do
127
+ @reply.fail "meh", 2
128
+ @reply.to_hash[:statuscode].should == 2
129
+ end
130
+
131
+ it "should have the correct statusmsg" do
132
+ @reply.fail "meh", 2
133
+ @reply.to_hash[:statusmsg].should == "meh"
134
+ end
135
+
136
+ it "should have the correct data" do
137
+ @reply[:foo] = :bar
138
+ @reply.to_hash[:data][:foo].should == :bar
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end