mcollective-client 2.0.0 → 2.2.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.
- data/lib/mcollective.rb +32 -23
- data/lib/mcollective/agent.rb +5 -0
- data/lib/mcollective/agents.rb +5 -16
- data/lib/mcollective/aggregate.rb +61 -0
- data/lib/mcollective/aggregate/base.rb +40 -0
- data/lib/mcollective/aggregate/result.rb +9 -0
- data/lib/mcollective/aggregate/result/base.rb +25 -0
- data/lib/mcollective/aggregate/result/collection_result.rb +19 -0
- data/lib/mcollective/aggregate/result/numeric_result.rb +13 -0
- data/lib/mcollective/application.rb +7 -4
- data/lib/mcollective/applications.rb +3 -14
- data/lib/mcollective/cache.rb +145 -0
- data/lib/mcollective/client.rb +10 -87
- data/lib/mcollective/config.rb +22 -8
- data/lib/mcollective/data.rb +87 -0
- data/lib/mcollective/data/base.rb +67 -0
- data/lib/mcollective/data/result.rb +40 -0
- data/lib/mcollective/ddl.rb +113 -0
- data/lib/mcollective/ddl/agentddl.rb +185 -0
- data/lib/mcollective/ddl/base.rb +220 -0
- data/lib/mcollective/ddl/dataddl.rb +56 -0
- data/lib/mcollective/ddl/discoveryddl.rb +52 -0
- data/lib/mcollective/ddl/validatorddl.rb +6 -0
- data/lib/mcollective/discovery.rb +143 -0
- data/lib/mcollective/generators.rb +7 -0
- data/lib/mcollective/generators/agent_generator.rb +51 -0
- data/lib/mcollective/generators/base.rb +46 -0
- data/lib/mcollective/generators/data_generator.rb +51 -0
- data/lib/mcollective/generators/templates/action_snippet.erb +13 -0
- data/lib/mcollective/generators/templates/data_input_snippet.erb +7 -0
- data/lib/mcollective/generators/templates/ddl.erb +8 -0
- data/lib/mcollective/generators/templates/plugin.erb +7 -0
- data/lib/mcollective/logger/console_logger.rb +15 -15
- data/lib/mcollective/matcher.rb +167 -0
- data/lib/mcollective/matcher/parser.rb +60 -25
- data/lib/mcollective/matcher/scanner.rb +156 -78
- data/lib/mcollective/message.rb +47 -6
- data/lib/mcollective/monkey_patches.rb +17 -0
- data/lib/mcollective/optionparser.rb +18 -1
- data/lib/mcollective/pluginmanager.rb +3 -3
- data/lib/mcollective/pluginpackager.rb +10 -3
- data/lib/mcollective/pluginpackager/agent_definition.rb +28 -20
- data/lib/mcollective/pluginpackager/standard_definition.rb +11 -9
- data/lib/mcollective/registration/base.rb +3 -1
- data/lib/mcollective/rpc.rb +18 -24
- data/lib/mcollective/rpc/agent.rb +37 -113
- data/lib/mcollective/rpc/client.rb +186 -64
- data/lib/mcollective/rpc/helpers.rb +42 -80
- data/lib/mcollective/rpc/progress.rb +3 -3
- data/lib/mcollective/rpc/reply.rb +37 -13
- data/lib/mcollective/rpc/request.rb +17 -6
- data/lib/mcollective/rpc/result.rb +9 -5
- data/lib/mcollective/rpc/stats.rb +71 -24
- data/lib/mcollective/security/base.rb +41 -34
- data/lib/mcollective/shell.rb +1 -1
- data/lib/mcollective/ssl.rb +34 -0
- data/lib/mcollective/util.rb +194 -23
- data/lib/mcollective/validator.rb +80 -0
- data/spec/fixtures/util/1.in +10 -0
- data/spec/fixtures/util/1.out +10 -0
- data/spec/fixtures/util/2.in +1 -0
- data/spec/fixtures/util/2.out +1 -0
- data/spec/fixtures/util/3.in +1 -0
- data/spec/fixtures/util/3.out +2 -0
- data/spec/fixtures/util/4.in +5 -0
- data/spec/fixtures/util/4.out +9 -0
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/agents_spec.rb +34 -19
- data/spec/unit/aggregate/base_spec.rb +57 -0
- data/spec/unit/aggregate/result/base_spec.rb +28 -0
- data/spec/unit/aggregate/result/collection_result_spec.rb +18 -0
- data/spec/unit/aggregate/result/numeric_result_spec.rb +22 -0
- data/spec/unit/aggregate_spec.rb +110 -0
- data/spec/unit/application_spec.rb +8 -3
- data/spec/unit/applications_spec.rb +2 -2
- data/spec/unit/cache_spec.rb +115 -0
- data/spec/unit/client_spec.rb +78 -0
- data/spec/unit/config_spec.rb +32 -34
- data/spec/unit/data/base_spec.rb +90 -0
- data/spec/unit/data/result_spec.rb +64 -0
- data/spec/unit/data_spec.rb +158 -0
- data/spec/unit/ddl/agentddl_spec.rb +217 -0
- data/spec/unit/{rpc/ddl_spec.rb → ddl/base_spec.rb} +238 -224
- data/spec/unit/ddl/dataddl_spec.rb +65 -0
- data/spec/unit/ddl/discoveryddl_spec.rb +58 -0
- data/spec/unit/ddl_spec.rb +84 -0
- data/spec/unit/discovery_spec.rb +196 -0
- data/spec/unit/facts/base_spec.rb +1 -1
- data/spec/unit/generators/agent_generator_spec.rb +72 -0
- data/spec/unit/generators/base_spec.rb +83 -0
- data/spec/unit/generators/data_generator_spec.rb +37 -0
- data/spec/unit/generators/snippets/agent_ddl +19 -0
- data/spec/unit/generators/snippets/data_ddl +20 -0
- data/spec/unit/logger/console_logger_spec.rb +76 -0
- data/spec/unit/logger/syslog_logger_spec.rb +2 -2
- data/spec/unit/matcher/parser_spec.rb +27 -10
- data/spec/unit/matcher/scanner_spec.rb +108 -5
- data/spec/unit/matcher_spec.rb +260 -0
- data/spec/unit/message_spec.rb +35 -13
- data/spec/unit/optionparser_spec.rb +2 -2
- data/spec/unit/pluginpackager/agent_definition_spec.rb +59 -42
- data/spec/unit/pluginpackager/standard_definition_spec.rb +10 -8
- data/spec/unit/pluginpackager_spec.rb +131 -0
- data/spec/unit/plugins/mcollective/aggregate/average_spec.rb +45 -0
- data/spec/unit/plugins/mcollective/aggregate/sum_spec.rb +31 -0
- data/spec/unit/plugins/mcollective/aggregate/summary_spec.rb +45 -0
- data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +1 -1
- data/spec/unit/plugins/mcollective/connector/rabbitmq_spec.rb +478 -0
- data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +2 -0
- data/spec/unit/plugins/mcollective/data/agent_data_spec.rb +43 -0
- data/spec/unit/plugins/mcollective/data/fstat_data_spec.rb +135 -0
- data/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb +48 -0
- data/spec/unit/plugins/mcollective/discovery/mc_spec.rb +40 -0
- data/spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb +41 -15
- data/spec/unit/plugins/mcollective/packagers/ospackage_spec.rb +1 -1
- data/spec/unit/plugins/mcollective/packagers/rpmpackage_packager_spec.rb +22 -38
- data/spec/unit/plugins/mcollective/validator/array_validator_spec.rb +19 -0
- data/spec/unit/plugins/mcollective/validator/ipv4address_validator_spec.rb +19 -0
- data/spec/unit/plugins/mcollective/validator/ipv6address_validator_spec.rb +19 -0
- data/spec/unit/plugins/mcollective/validator/length_validator_spec.rb +19 -0
- data/spec/unit/plugins/mcollective/validator/regex_validator_spec.rb +19 -0
- data/spec/unit/plugins/mcollective/validator/shellsafe_validator_spec.rb +21 -0
- data/spec/unit/plugins/mcollective/validator/typecheck_validator_spec.rb +23 -0
- data/spec/unit/registration/base_spec.rb +1 -1
- data/spec/unit/rpc/actionrunner_spec.rb +2 -2
- data/spec/unit/rpc/agent_spec.rb +41 -65
- data/spec/unit/rpc/client_spec.rb +430 -134
- data/spec/unit/rpc/reply_spec.rb +31 -1
- data/spec/unit/rpc/request_spec.rb +33 -12
- data/spec/unit/rpc/result_spec.rb +7 -0
- data/spec/unit/rpc/stats_spec.rb +14 -14
- data/spec/unit/rpc_spec.rb +16 -0
- data/spec/unit/security/base_spec.rb +8 -8
- data/spec/unit/ssl_spec.rb +20 -2
- data/spec/unit/string_spec.rb +15 -0
- data/spec/unit/util_spec.rb +141 -21
- data/spec/unit/validator_spec.rb +67 -0
- metadata +145 -7
- data/lib/mcollective/rpc/ddl.rb +0 -258
@@ -0,0 +1,158 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
describe Data do
|
7
|
+
describe "#load_data_sources" do
|
8
|
+
it "should use the pluginmanager to load data sources" do
|
9
|
+
PluginManager.expects(:find_and_load).with("data").returns([])
|
10
|
+
Data.load_data_sources
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should remove plugins that should not be active on this node" do
|
14
|
+
PluginManager.expects(:find_and_load).with("data").returns(["rspec_data"])
|
15
|
+
PluginManager.expects(:grep).returns(["rspec_data"])
|
16
|
+
PluginManager.expects(:delete).with("rspec_data")
|
17
|
+
|
18
|
+
ddl = mock
|
19
|
+
ddl.stubs(:meta).returns({:timeout => 1})
|
20
|
+
DDL.stubs(:new).returns(ddl)
|
21
|
+
Data::Base.expects(:activate?).returns(false)
|
22
|
+
PluginManager.expects("[]").with("rspec_data").returns(Data::Base.new)
|
23
|
+
Data.load_data_sources
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should handle exceptions and delete broken plugins" do
|
27
|
+
PluginManager.expects(:find_and_load).with("data").returns(["rspec_data"])
|
28
|
+
PluginManager.expects(:grep).returns(["rspec_data"])
|
29
|
+
PluginManager.expects(:delete).with("rspec_data")
|
30
|
+
|
31
|
+
ddl = mock
|
32
|
+
ddl.stubs(:meta).returns({:timeout => 1})
|
33
|
+
DDL.stubs(:new).returns(ddl)
|
34
|
+
Data::Base.expects(:activate?).raises("rspec failure")
|
35
|
+
Log.expects(:debug).once.with("Disabling data plugin rspec_data due to exception RuntimeError: rspec failure")
|
36
|
+
PluginManager.expects("[]").with("rspec_data").returns(Data::Base.new)
|
37
|
+
Data.load_data_sources
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#ddl" do
|
42
|
+
it "should load the right data ddl" do
|
43
|
+
DDL.expects(:new).with("fstat_data", :data).times(3)
|
44
|
+
Data.ddl("fstat")
|
45
|
+
Data.ddl("fstat_data")
|
46
|
+
Data.ddl(:fstat)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#pluginname" do
|
51
|
+
it "should return the correct plugin name" do
|
52
|
+
Data.pluginname("Rspec").should == "rspec_data"
|
53
|
+
Data.pluginname("Rspec_data").should == "rspec_data"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#[]" do
|
58
|
+
it "should return the correct plugin" do
|
59
|
+
PluginManager.expects("[]").with("rspec_data").times(4)
|
60
|
+
Data["Rspec"]
|
61
|
+
Data["rspec"]
|
62
|
+
Data["rspec_data"]
|
63
|
+
Data["rspec_Data"]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#method_missing" do
|
68
|
+
it "should raise errors for unknown plugins" do
|
69
|
+
PluginManager.expects("include?").with("rspec_data").returns(false)
|
70
|
+
expect { Data.rspec_data }.to raise_error(NoMethodError)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should do a lookup on the right plugin" do
|
74
|
+
rspec_data = mock
|
75
|
+
rspec_data.expects(:lookup).returns("rspec")
|
76
|
+
|
77
|
+
PluginManager.expects("include?").with("rspec_data").returns(true)
|
78
|
+
PluginManager.expects("[]").with("rspec_data").returns(rspec_data)
|
79
|
+
|
80
|
+
Data.rspec_data("rspec").should == "rspec"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#ddl_transform_intput" do
|
85
|
+
it "should convert boolean data" do
|
86
|
+
ddl = mock
|
87
|
+
ddl.stubs(:entities).returns({:data => {:input => {:query => {:type => :boolean}}}})
|
88
|
+
Data.ddl_transform_input(ddl, "1").should == true
|
89
|
+
Data.ddl_transform_input(ddl, "0").should == false
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should conver numeric data" do
|
93
|
+
ddl = mock
|
94
|
+
ddl.stubs(:entities).returns({:data => {:input => {:query => {:type => :number}}}})
|
95
|
+
Data.ddl_transform_input(ddl, "1").should == 1
|
96
|
+
Data.ddl_transform_input(ddl, "0").should == 0
|
97
|
+
Data.ddl_transform_input(ddl, "1.1").should == 1.1
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return the original input on any failure" do
|
101
|
+
ddl = mock
|
102
|
+
ddl.expects(:entities).raises("rspec failure")
|
103
|
+
Data.ddl_transform_input(ddl, 1).should == 1
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#ddl_has_output?" do
|
108
|
+
it "should correctly verify output keys" do
|
109
|
+
ddl = mock
|
110
|
+
ddl.stubs(:entities).returns({:data => {:output => {:rspec => {}}}})
|
111
|
+
Data.ddl_has_output?(ddl, "rspec").should == true
|
112
|
+
Data.ddl_has_output?(ddl, :rspec).should == true
|
113
|
+
Data.ddl_has_output?(ddl, :foo).should == false
|
114
|
+
Data.ddl_has_output?(ddl, "foo").should == false
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should return false for any exception" do
|
118
|
+
ddl = mock
|
119
|
+
ddl.stubs(:entities).returns(nil)
|
120
|
+
Data.ddl_has_output?(ddl, "rspec").should == false
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "#ddl_validate" do
|
125
|
+
before do
|
126
|
+
@ddl = mock
|
127
|
+
@ddl.expects(:meta).returns({:name => "rspec test"})
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should ensure the ddl has a dataquery" do
|
131
|
+
@ddl.expects(:entities).returns({})
|
132
|
+
expect { Data.ddl_validate(@ddl, "rspec") }.to raise_error("No dataquery has been defined in the DDL for data plugin rspec test")
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should ensure the ddl has an input" do
|
136
|
+
@ddl.expects(:entities).returns({:data => {:input => {}, :output => {}}})
|
137
|
+
expect { Data.ddl_validate(@ddl, "rspec") }.to raise_error("No :query input has been defined in the DDL for data plugin rspec test")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should ensure the ddl has output" do
|
141
|
+
@ddl.expects(:entities).returns({:data => {:input => {:query => {}}, :output => {}}})
|
142
|
+
expect { Data.ddl_validate(@ddl, "rspec") }.to raise_error("No output has been defined in the DDL for data plugin rspec test")
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should skip optional arguments that were not supplied" do
|
146
|
+
@ddl.expects(:entities).returns({:data => {:input => {:query => {:optional => true}}, :output => {:test => {}}}})
|
147
|
+
@ddl.expects(:validate_input_argument).never
|
148
|
+
Data.ddl_validate(@ddl, nil).should == true
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should validate the argument" do
|
152
|
+
@ddl.expects(:entities).returns({:data => {:input => {:query => {}}, :output => {:test => {}}}})
|
153
|
+
@ddl.expects(:validate_input_argument).returns("rspec validated")
|
154
|
+
Data.ddl_validate(@ddl, "rspec").should == "rspec validated"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
module DDL
|
7
|
+
describe AgentDDL do
|
8
|
+
before :each do
|
9
|
+
Cache.delete!(:ddl) rescue nil
|
10
|
+
@ddl = DDL.new("rspec", :agent, false)
|
11
|
+
@ddl.metadata(:name => "name", :description => "description", :author => "author", :license => "license", :version => "version", :url => "url", :timeout => "timeout")
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#input" do
|
15
|
+
it "should validate that an :optional property is set" do
|
16
|
+
expect { @ddl.input(:x, {:y => 1}) }.to raise_error("Input needs a :optional property")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#validate_rpc_request" do
|
21
|
+
it "should ensure the action is known" do
|
22
|
+
@ddl.action(:test, :description => "rspec")
|
23
|
+
|
24
|
+
expect {
|
25
|
+
@ddl.validate_rpc_request(:fail, {})
|
26
|
+
}.to raise_error("Attempted to call action fail for rspec but it's not declared in the DDL")
|
27
|
+
|
28
|
+
@ddl.validate_rpc_request(:test, {})
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should check all required arguments are present" do
|
32
|
+
@ddl.action(:test, :description => "rspec")
|
33
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
34
|
+
@ddl.input(:optional, :prompt => "prompt", :description => "descr",
|
35
|
+
:type => :string, :optional => true, :validation => "",
|
36
|
+
:maxlength => 1)
|
37
|
+
@ddl.input(:required, :prompt => "prompt", :description => "descr",
|
38
|
+
:type => :string, :optional => false, :validation => "",
|
39
|
+
:maxlength => 1)
|
40
|
+
|
41
|
+
expect {
|
42
|
+
@ddl.validate_rpc_request(:test, {})
|
43
|
+
}.to raise_error("Action test needs a required argument")
|
44
|
+
|
45
|
+
@ddl.validate_rpc_request(:test, {:required => "f"}).should == true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should input validate every supplied key" do
|
49
|
+
@ddl.action(:test, :description => "rspec")
|
50
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
51
|
+
@ddl.input(:optional, :prompt => "prompt", :description => "descr",
|
52
|
+
:type => :string, :optional => true, :validation => "",
|
53
|
+
:maxlength => 1)
|
54
|
+
@ddl.input(:required, :prompt => "prompt", :description => "descr",
|
55
|
+
:type => :string, :optional => false, :validation => "",
|
56
|
+
:maxlength => 1)
|
57
|
+
|
58
|
+
|
59
|
+
@ddl.expects(:validate_input_argument).with(@ddl.entities[:test][:input], :required, "f")
|
60
|
+
@ddl.expects(:validate_input_argument).with(@ddl.entities[:test][:input], :optional, "f")
|
61
|
+
|
62
|
+
@ddl.validate_rpc_request(:test, {:required => "f", :optional => "f"}).should == true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#is_function" do
|
67
|
+
before :each do
|
68
|
+
PluginManager.expects(:find).with("aggregate").returns(["plugin"])
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return true if the aggregate function is present" do
|
72
|
+
@ddl.is_function?("plugin").should == true
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return false if the aggregate function is not present" do
|
76
|
+
@ddl.is_function?("no_plugin").should == false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#method_missing" do
|
81
|
+
it "should call super if the aggregate plugin isn't present" do
|
82
|
+
expect{
|
83
|
+
@ddl.test
|
84
|
+
}.to raise_error(NoMethodError)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should call super if @process_aggregate_function is false" do
|
88
|
+
expect{
|
89
|
+
result = @ddl.test(:value)
|
90
|
+
}.to raise_error(NoMethodError)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return the function hash" do
|
94
|
+
Config.instance.mode = :client
|
95
|
+
@ddl.instance_variable_set(:@process_aggregate_functions, true)
|
96
|
+
result = @ddl.method_missing(:test_function, :rspec)
|
97
|
+
result.should == {:args => [:rspec], :function => :test_function }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#actions" do
|
102
|
+
it "should return the correct list of actions" do
|
103
|
+
@ddl.action(:test1, :description => "rspec")
|
104
|
+
@ddl.action(:test2, :description => "rspec")
|
105
|
+
|
106
|
+
@ddl.actions.sort.should == [:test1, :test2]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#action_interface" do
|
111
|
+
it "should return the correct interface" do
|
112
|
+
@ddl.action(:test1, :description => "rspec")
|
113
|
+
@ddl.action_interface(:test1).should == {:description=>"rspec", :output=>{}, :input=>{}, :action=>:test1, :display=>:failed}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "#display" do
|
118
|
+
it "should ensure a valid display property is set" do
|
119
|
+
@ddl.action(:test, :description => "rspec")
|
120
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
121
|
+
|
122
|
+
[:ok, :failed, :flatten, :always].each do |display|
|
123
|
+
@ddl.display(display)
|
124
|
+
|
125
|
+
action = @ddl.action_interface(:test)
|
126
|
+
action[:display].should == display
|
127
|
+
end
|
128
|
+
|
129
|
+
expect {
|
130
|
+
@ddl.display(:foo)
|
131
|
+
}.to raise_error(/Display preference foo is not valid/)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "#summarize" do
|
136
|
+
before :each do
|
137
|
+
@block_result = nil
|
138
|
+
@block = Proc.new{@block_result = :success}
|
139
|
+
end
|
140
|
+
|
141
|
+
after :each do
|
142
|
+
@block_result = nil
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should call the block parameter if config mode is not server" do
|
146
|
+
Config.instance.mode = :client
|
147
|
+
result = @ddl.summarize(&@block)
|
148
|
+
@block_result.should == :success
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should not call the block parameter if config mode is server" do
|
152
|
+
Config.instance.mode = :server
|
153
|
+
result = @ddl.summarize(&@block)
|
154
|
+
@block_result.should == nil
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#aggregate" do
|
159
|
+
it "should raise an exception if aggregate format isn't a hash" do
|
160
|
+
expect{
|
161
|
+
@ddl.aggregate(:foo, :format)
|
162
|
+
}.to raise_error(DDLValidationError, "Formats supplied to aggregation functions should be a hash")
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should raise an exception if format hash does not include a :format key" do
|
166
|
+
expect{
|
167
|
+
@ddl.aggregate(:foo, {})
|
168
|
+
}.to raise_error(DDLValidationError, "Formats supplied to aggregation functions must have a :format key")
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should raise an exception if aggregate function is not a hash" do
|
172
|
+
expect{
|
173
|
+
@ddl.aggregate(:foo)
|
174
|
+
}.to raise_error(DDLValidationError, "Functions supplied to aggregate should be a hash")
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should raise an exception if function hash does not include a :args key" do
|
178
|
+
expect{
|
179
|
+
@ddl.stubs(:entities).returns({nil => {:action => :foo}})
|
180
|
+
@ddl.aggregate({})
|
181
|
+
}.to raise_error(DDLValidationError, "aggregate method for action 'foo' missing a function parameter")
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should correctly add an aggregate function to the function array" do
|
185
|
+
@ddl.stubs(:entities).returns({nil => {:aggregate => nil}})
|
186
|
+
@ddl.aggregate({:function => :foo, :args => [:bar]})
|
187
|
+
@ddl.entities.should == {nil => {:aggregate => [{:function => :foo, :args => [:bar]}]}}
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "#action" do
|
192
|
+
it "should ensure a description is set" do
|
193
|
+
expect {
|
194
|
+
@ddl.action("act", {})
|
195
|
+
}.to raise_error("Action needs a :description property")
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should create a default action structure" do
|
199
|
+
@ddl.action("act", :description => "rspec")
|
200
|
+
|
201
|
+
action = @ddl.action_interface("act")
|
202
|
+
|
203
|
+
action.class.should == Hash
|
204
|
+
action[:action].should == "act"
|
205
|
+
action[:input].should == {}
|
206
|
+
action[:output].should == {}
|
207
|
+
action[:display].should == :failed
|
208
|
+
action[:description].should == "rspec"
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should call a block if one is given and set the correct action name" do
|
212
|
+
@ddl.action("act", :description => "rspec") { @ddl.instance_variable_get("@current_entity").should == "act" }
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
@@ -3,22 +3,230 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
module MCollective
|
6
|
-
module
|
7
|
-
describe
|
6
|
+
module DDL
|
7
|
+
describe Base do
|
8
8
|
before :each do
|
9
|
-
|
9
|
+
Cache.delete!(:ddl) rescue nil
|
10
|
+
@ddl = DDL.new("rspec", :agent, false)
|
11
|
+
@ddl.metadata(:name => "name", :description => "description", :author => "author", :license => "license", :version => "version", :url => "url", :timeout => "timeout")
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#template_for_plugintype" do
|
15
|
+
it "should return the backward compat path for agent ddls" do
|
16
|
+
@ddl.template_for_plugintype.should == "rpc-help.erb"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return correct new path for other ddls" do
|
20
|
+
@ddl.instance_variable_set("@plugintype", :data)
|
21
|
+
@ddl.template_for_plugintype.should == "data-help.erb"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#help" do
|
26
|
+
it "should use conventional template paths when none is provided" do
|
27
|
+
File.expects(:read).with("/etc/mcollective/rpc-help.erb").returns("rspec")
|
28
|
+
File.expects(:read).with("/etc/mcollective/metadata-help.erb").returns("rspec")
|
29
|
+
@ddl.help.should == "rspec"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should use template from help template path when provided template name is not an absolute file path" do
|
33
|
+
File.expects(:read).with("/etc/mcollective/foo").returns("rspec")
|
34
|
+
File.expects(:read).with("/etc/mcollective/metadata-help.erb").returns("rspec")
|
35
|
+
@ddl.help("foo").should == "rspec"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should use supplied template path when one is provided" do
|
39
|
+
File.expects(:read).with("/foo").returns("rspec")
|
40
|
+
File.expects(:read).with("/etc/mcollective/metadata-help.erb").returns("rspec")
|
41
|
+
@ddl.help("/foo").should == "rspec"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should correctly execute the template with a valid binding" do
|
45
|
+
@ddl.instance_variable_set("@meta", "meta")
|
46
|
+
@ddl.instance_variable_set("@entities", "actions")
|
47
|
+
File.expects(:read).with("/template").returns("<%= meta %>:<%= entities %>")
|
48
|
+
File.expects(:read).with("/etc/mcollective/metadata-help.erb").returns("rspec")
|
49
|
+
@ddl.help("/template").should == "meta:actions"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#validate_input_arguments" do
|
54
|
+
before :all do
|
55
|
+
Config.instance.stubs(:configured).returns(true)
|
56
|
+
Config.instance.stubs(:libdir).returns([File.join(File.dirname(__FILE__), "../../../plugins")])
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should ensure strings are String" do
|
60
|
+
@ddl.action(:string, :description => "rspec")
|
61
|
+
@ddl.instance_variable_set("@current_entity", :string)
|
62
|
+
@ddl.input(:string, :prompt => "prompt", :description => "descr",
|
63
|
+
:type => :string, :optional => true, :validation => "",
|
64
|
+
:maxlength => 1)
|
65
|
+
|
66
|
+
expect {
|
67
|
+
@ddl.validate_input_argument(@ddl.entities[:string][:input], :string, 1)
|
68
|
+
}.to raise_error("Cannot validate input: value should be a string")
|
69
|
+
|
70
|
+
@ddl.validate_input_argument(@ddl.entities[:string][:input], :string, "1")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should ensure strings are not longer than maxlength" do
|
74
|
+
@ddl.action(:string, :description => "rspec")
|
75
|
+
@ddl.instance_variable_set("@current_entity", :string)
|
76
|
+
@ddl.input(:string, :prompt => "prompt", :description => "descr",
|
77
|
+
:type => :string, :optional => true, :validation => "",
|
78
|
+
:maxlength => 1)
|
79
|
+
|
80
|
+
expect {
|
81
|
+
@ddl.validate_input_argument(@ddl.entities[:string][:input], :string, "too long")
|
82
|
+
}.to raise_error("Cannot validate input: Input string is longer than 1 character(s)")
|
83
|
+
|
84
|
+
@ddl.validate_input_argument(@ddl.entities[:string][:input], :string, "1")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should validate strings using regular expressions" do
|
88
|
+
@ddl.action(:string, :description => "rspec")
|
89
|
+
@ddl.instance_variable_set("@current_entity", :string)
|
90
|
+
@ddl.input(:string, :prompt => "prompt", :description => "descr",
|
91
|
+
:type => :string, :optional => true, :validation => "^regex$",
|
92
|
+
:maxlength => 100)
|
93
|
+
|
94
|
+
expect {
|
95
|
+
@ddl.validate_input_argument(@ddl.entities[:string][:input], :string, "doesnt validate")
|
96
|
+
}.to raise_error("Cannot validate input: value should match ^regex$")
|
97
|
+
|
98
|
+
@ddl.validate_input_argument(@ddl.entities[:string][:input], :string, "regex")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should validate list arguments correctly" do
|
102
|
+
@ddl.action(:list, :description => "rspec")
|
103
|
+
@ddl.instance_variable_set("@current_entity", :list)
|
104
|
+
@ddl.input(:list, :prompt => "prompt", :description => "descr",
|
105
|
+
:type => :list, :optional => true, :list => [1,2])
|
106
|
+
|
107
|
+
expect {
|
108
|
+
@ddl.validate_input_argument(@ddl.entities[:list][:input], :list, 3)
|
109
|
+
}.to raise_error("Cannot validate input: value should be one of 1, 2")
|
110
|
+
|
111
|
+
@ddl.validate_input_argument(@ddl.entities[:list][:input], :list, 1)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should validate boolean arguments correctly" do
|
115
|
+
@ddl.action(:bool, :description => "rspec")
|
116
|
+
@ddl.instance_variable_set("@current_entity", :bool)
|
117
|
+
@ddl.input(:bool, :prompt => "prompt", :description => "descr",
|
118
|
+
:type => :boolean, :optional => true)
|
119
|
+
|
120
|
+
expect {
|
121
|
+
@ddl.validate_input_argument(@ddl.entities[:bool][:input], :bool, 3)
|
122
|
+
}.to raise_error("Cannot validate input: value should be a boolean")
|
123
|
+
|
124
|
+
@ddl.validate_input_argument(@ddl.entities[:bool][:input], :bool, true)
|
125
|
+
@ddl.validate_input_argument(@ddl.entities[:bool][:input], :bool, false)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should validate integer arguments correctly" do
|
129
|
+
@ddl.action(:test, :description => "rspec")
|
130
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
131
|
+
@ddl.input(:int, :prompt => "prompt", :description => "descr",
|
132
|
+
:type => :integer, :optional => true)
|
133
|
+
|
134
|
+
expect {
|
135
|
+
@ddl.validate_input_argument(@ddl.entities[:test][:input], :int, "1")
|
136
|
+
}.to raise_error("Cannot validate input: value should be a integer")
|
137
|
+
|
138
|
+
expect {
|
139
|
+
@ddl.validate_input_argument(@ddl.entities[:test][:input], :int, 1.1)
|
140
|
+
}.to raise_error("Cannot validate input: value should be a integer")
|
141
|
+
|
142
|
+
@ddl.validate_input_argument(@ddl.entities[:test][:input], :int, 1)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should validate float arguments correctly" do
|
146
|
+
@ddl.action(:test, :description => "rspec")
|
147
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
148
|
+
@ddl.input(:float, :prompt => "prompt", :description => "descr",
|
149
|
+
:type => :float, :optional => true)
|
150
|
+
|
151
|
+
expect {
|
152
|
+
@ddl.validate_input_argument(@ddl.entities[:test][:input], :float, "1")
|
153
|
+
}.to raise_error("Cannot validate input: value should be a float")
|
154
|
+
|
155
|
+
expect {
|
156
|
+
@ddl.validate_input_argument(@ddl.entities[:test][:input], :float, 1)
|
157
|
+
}.to raise_error("Cannot validate input: value should be a float")
|
158
|
+
|
159
|
+
@ddl.validate_input_argument(@ddl.entities[:test][:input], :float, 1.1)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should validate number arguments correctly" do
|
163
|
+
@ddl.action(:test, :description => "rspec")
|
164
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
165
|
+
@ddl.input(:number, :prompt => "prompt", :description => "descr",
|
166
|
+
:type => :number, :optional => true)
|
167
|
+
|
168
|
+
expect {
|
169
|
+
@ddl.validate_input_argument(@ddl.entities[:test][:input], :number, "1")
|
170
|
+
}.to raise_error("Cannot validate input: value should be a number")
|
171
|
+
|
172
|
+
@ddl.validate_input_argument(@ddl.entities[:test][:input], :number, 1)
|
173
|
+
@ddl.validate_input_argument(@ddl.entities[:test][:input], :number, 1.1)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "#requires" do
|
178
|
+
it "should only accept hashes as arguments" do
|
179
|
+
expect { @ddl.requires(1) }.to raise_error(/should be a hash/)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should only accept valid requirement types" do
|
183
|
+
expect { @ddl.requires(:rspec => "1") }.to raise_error(/is not a valid requirement/)
|
184
|
+
@ddl.requires(:mcollective => "1.0.0")
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should save the requirement" do
|
188
|
+
@ddl.requires(:mcollective => "1.0.0")
|
189
|
+
|
190
|
+
@ddl.requirements.should == {:mcollective => "1.0.0"}
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "#validate_requirements" do
|
195
|
+
it "should fail for older versions of mcollective" do
|
196
|
+
Util.stubs(:mcollective_version).returns("0.1")
|
197
|
+
expect { @ddl.requires(:mcollective => "2.0") }.to raise_error(/requires.+version 2.0/)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should pass for newer versions of mcollective" do
|
201
|
+
Util.stubs(:mcollective_version).returns("2.0")
|
202
|
+
@ddl.requires(:mcollective => "0.1")
|
203
|
+
@ddl.validate_requirements.should == true
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should bypass checks in development" do
|
207
|
+
Util.stubs(:mcollective_version).returns("@DEVELOPMENT_VERSION@")
|
208
|
+
Log.expects(:warn).with(regexp_matches(/skipped in development/))
|
209
|
+
@ddl.requires(:mcollective => "0.1")
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "#loaddlfile" do
|
214
|
+
it "should raise the correct error when a ddl isnt present" do
|
215
|
+
@ddl.expects(:findddlfile).returns(false)
|
216
|
+
expect { @ddl.loadddlfile }.to raise_error("Can't find DDL for agent plugin 'rspec'")
|
217
|
+
end
|
10
218
|
end
|
11
219
|
|
12
220
|
describe "#findddlfile" do
|
13
221
|
it "should construct the correct ddl file name" do
|
14
|
-
Config.
|
222
|
+
Config.instance.expects(:libdir).returns(["/nonexisting"])
|
15
223
|
File.expects("exist?").with("/nonexisting/mcollective/agent/foo.ddl").returns(false)
|
16
224
|
|
17
225
|
@ddl.findddlfile("foo").should == false
|
18
226
|
end
|
19
227
|
|
20
228
|
it "should check each libdir for a ddl file" do
|
21
|
-
Config.
|
229
|
+
Config.instance.expects(:libdir).returns(["/nonexisting1", "/nonexisting2"])
|
22
230
|
File.expects("exist?").with("/nonexisting1/mcollective/agent/foo.ddl").returns(false)
|
23
231
|
File.expects("exist?").with("/nonexisting2/mcollective/agent/foo.ddl").returns(false)
|
24
232
|
|
@@ -26,12 +234,19 @@ module MCollective
|
|
26
234
|
end
|
27
235
|
|
28
236
|
it "should return the ddl file path if found" do
|
29
|
-
Config.
|
237
|
+
Config.instance.expects(:libdir).returns(["/nonexisting"])
|
30
238
|
File.expects("exist?").with("/nonexisting/mcollective/agent/foo.ddl").returns(true)
|
31
239
|
Log.expects(:debug).with("Found foo ddl at /nonexisting/mcollective/agent/foo.ddl")
|
32
240
|
|
33
241
|
@ddl.findddlfile("foo").should == "/nonexisting/mcollective/agent/foo.ddl"
|
34
242
|
end
|
243
|
+
|
244
|
+
it "should default to the current plugin and type" do
|
245
|
+
Config.instance.expects(:libdir).returns(["/nonexisting"])
|
246
|
+
File.expects("exist?").with("/nonexisting/mcollective/agent/rspec.ddl").returns(true)
|
247
|
+
|
248
|
+
@ddl.findddlfile.should == "/nonexisting/mcollective/agent/rspec.ddl"
|
249
|
+
end
|
35
250
|
end
|
36
251
|
|
37
252
|
describe "#metadata" do
|
@@ -44,7 +259,7 @@ module MCollective
|
|
44
259
|
|
45
260
|
expect {
|
46
261
|
@ddl.metadata(metadata)
|
47
|
-
}.to raise_error("Metadata needs a :#{tst}")
|
262
|
+
}.to raise_error("Metadata needs a :#{tst} property")
|
48
263
|
end
|
49
264
|
end
|
50
265
|
|
@@ -57,35 +272,10 @@ module MCollective
|
|
57
272
|
end
|
58
273
|
end
|
59
274
|
|
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
275
|
describe "#input" do
|
86
276
|
it "should ensure required properties are set" do
|
87
277
|
@ddl.action(:test, :description => "rspec")
|
88
|
-
@ddl.instance_variable_set("@
|
278
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
89
279
|
|
90
280
|
[:prompt, :description, :type, :optional].each do |arg|
|
91
281
|
args = {:prompt => "prompt", :description => "descr", :type => "type", :optional => true}
|
@@ -93,7 +283,7 @@ module MCollective
|
|
93
283
|
|
94
284
|
expect {
|
95
285
|
@ddl.input(:test, args)
|
96
|
-
}.to raise_error("Input needs a :#{arg}")
|
286
|
+
}.to raise_error("Input needs a :#{arg} property")
|
97
287
|
end
|
98
288
|
|
99
289
|
@ddl.input(:test, {:prompt => "prompt", :description => "descr", :type => "type", :optional => true})
|
@@ -101,7 +291,7 @@ module MCollective
|
|
101
291
|
|
102
292
|
it "should ensure strings have a validation and maxlength" do
|
103
293
|
@ddl.action(:test, :description => "rspec")
|
104
|
-
@ddl.instance_variable_set("@
|
294
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
105
295
|
|
106
296
|
expect {
|
107
297
|
@ddl.input(:test, :prompt => "prompt", :description => "descr",
|
@@ -119,7 +309,7 @@ module MCollective
|
|
119
309
|
|
120
310
|
it "should ensure lists have a list argument" do
|
121
311
|
@ddl.action(:test, :description => "rspec")
|
122
|
-
@ddl.instance_variable_set("@
|
312
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
123
313
|
|
124
314
|
expect {
|
125
315
|
@ddl.input(:test, :prompt => "prompt", :description => "descr",
|
@@ -132,7 +322,7 @@ module MCollective
|
|
132
322
|
|
133
323
|
it "should save correct data for a list input" do
|
134
324
|
@ddl.action(:test, :description => "rspec")
|
135
|
-
@ddl.instance_variable_set("@
|
325
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
136
326
|
@ddl.input(:test, :prompt => "prompt", :description => "descr",
|
137
327
|
:type => :list, :optional => true, :list => [])
|
138
328
|
|
@@ -147,7 +337,7 @@ module MCollective
|
|
147
337
|
|
148
338
|
it "should save correct data for a string input" do
|
149
339
|
@ddl.action(:test, :description => "rspec")
|
150
|
-
@ddl.instance_variable_set("@
|
340
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
151
341
|
@ddl.input(:test, :prompt => "prompt", :description => "descr",
|
152
342
|
:type => :string, :optional => true, :validation => "",
|
153
343
|
:maxlength => 1)
|
@@ -166,7 +356,7 @@ module MCollective
|
|
166
356
|
describe "#output" do
|
167
357
|
it "should ensure a :description is set" do
|
168
358
|
@ddl.action(:test, :description => "rspec")
|
169
|
-
@ddl.instance_variable_set("@
|
359
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
170
360
|
|
171
361
|
expect {
|
172
362
|
@ddl.output(:test, {})
|
@@ -175,7 +365,7 @@ module MCollective
|
|
175
365
|
|
176
366
|
it "should ensure a :display_as is set" do
|
177
367
|
@ddl.action(:test, :description => "rspec")
|
178
|
-
@ddl.instance_variable_set("@
|
368
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
179
369
|
|
180
370
|
expect {
|
181
371
|
@ddl.output(:test, {:description => "rspec"})
|
@@ -184,205 +374,29 @@ module MCollective
|
|
184
374
|
|
185
375
|
it "should save correct data for an output" do
|
186
376
|
@ddl.action(:test, :description => "rspec")
|
187
|
-
@ddl.instance_variable_set("@
|
377
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
188
378
|
|
189
|
-
@ddl.output(:test, {:description => "rspec", :display_as => "RSpec"})
|
379
|
+
@ddl.output(:test, {:description => "rspec", :display_as => "RSpec", :default => "default"})
|
190
380
|
|
191
381
|
action = @ddl.action_interface(:test)
|
192
382
|
|
193
383
|
action[:output][:test][:description].should == "rspec"
|
194
384
|
action[:output][:test][:display_as].should == "RSpec"
|
385
|
+
action[:output][:test][:default].should == "default"
|
195
386
|
end
|
196
|
-
end
|
197
387
|
|
198
|
-
|
199
|
-
it "should ensure a valid display property is set" do
|
388
|
+
it "should set unsupplied defaults to our internal unset representation" do
|
200
389
|
@ddl.action(:test, :description => "rspec")
|
201
|
-
@ddl.instance_variable_set("@
|
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
|
390
|
+
@ddl.instance_variable_set("@current_entity", :test)
|
209
391
|
|
210
|
-
|
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")
|
392
|
+
@ddl.output(:test, {:description => "rspec", :display_as => "RSpec"})
|
229
393
|
|
230
|
-
@ddl.
|
231
|
-
end
|
232
|
-
end
|
394
|
+
action = @ddl.action_interface(:test)
|
233
395
|
|
234
|
-
|
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}
|
396
|
+
action[:output][:test][:default].should == nil
|
238
397
|
end
|
239
398
|
end
|
240
399
|
|
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
400
|
end
|
387
401
|
end
|
388
402
|
end
|