icontrol 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ class EndpointHelper
2
+ # returns an endpoint to be passed to fakeweb
3
+ def self.wsdl_endpoint(class_name)
4
+ fqn = class_name.split("::")
5
+ return self.soap_endpoint + "?WSDL=#{fqn[1]}.#{fqn[2]}"
6
+ end
7
+
8
+ def self.soap_endpoint
9
+ icontrol_base = IControl.config[:base_url].split("://")
10
+ return icontrol_base[0] + "://" + IControl.config[:user] + ":" + IControl.config[:password] + "@" + icontrol_base[1..-1].join
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,14 @@
1
+ require "yaml"
2
+ require "erb"
3
+
4
+ class SOAPFixture
5
+
6
+ @@responses = {}
7
+
8
+ def self.response(operation)
9
+ return @@responses[operation] if @@responses[operation]
10
+ file = File.read File.dirname(__FILE__) + "/xml/#{operation}_response.xml"
11
+ @@responses[operation] = file
12
+ end
13
+
14
+ end
@@ -0,0 +1,15 @@
1
+ require "yaml"
2
+ require "erb"
3
+
4
+ class WSDLFixture
5
+
6
+ @@wsdl = {}
7
+
8
+ def self.wsdl(wsdl)
9
+ return @@wsdl[wsdl] if @@wsdl[wsdl]
10
+ file = File.read File.dirname(__FILE__) + "/xml/#{wsdl}.xml"
11
+ @@wsdl[wsdl] = file
12
+ end
13
+
14
+ end
15
+
@@ -0,0 +1,119 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ describe IControl::LocalLB::Pool do
3
+
4
+ before do
5
+ @pool = IControl::LocalLB::Pool.find("pool_test1")
6
+ end
7
+
8
+ describe "constructor" do
9
+ it "has an initializer that the attributes" do
10
+ pool = IControl::LocalLB::Pool.new(:id => "pool_test1")
11
+ pool.class.should be(IControl::LocalLB::Pool)
12
+ end
13
+ end
14
+
15
+ describe "find method" do
16
+
17
+ describe "when pool is not found" do
18
+ it "should return nil" do
19
+ IControl::LocalLB::Pool.find("none").should be(nil)
20
+ end
21
+ end
22
+
23
+ describe "when pool is found" do
24
+ it "has to return a Pool Object" do
25
+ @pool.class.should be(IControl::LocalLB::Pool)
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+
32
+ describe "create method" do
33
+
34
+ it "should return the created object if the creation was successful" do
35
+ @pools = IControl::LocalLB::Pool.find(:all)
36
+ @pools.map(&:id).include?("new_test_pool").should be(false)
37
+ new_created = IControl::LocalLB::Pool.create(
38
+ :id => "new_test_pool",
39
+ :lb_method => "LB_METHOD_ROUND_ROBIN",
40
+ :members => [
41
+ IControl::Common::IPPortDefinition.new(:address => "192.168.6.122",:port=>"4036"),
42
+ IControl::Common::IPPortDefinition.new(:address => "192.168.6.123",:port=>"4036")
43
+ ]
44
+ )
45
+
46
+ new_created.id.should == "new_test_pool"
47
+ new_created.lb_method.should == "LB_METHOD_ROUND_ROBIN"
48
+ new_created.members.class.should be(Array)
49
+ new_created.members[0].class.should be(IControl::Common::IPPortDefinition)
50
+ # @pools = IControl::LocalLB::Pool.find(:all)
51
+ # @pools.map(&:id).include?("new_test_pool").should be(true)
52
+ end
53
+
54
+
55
+ it "should raise an exception when the pool already existed" do
56
+ lambda{
57
+ IControl::LocalLB::Pool.create(
58
+ :id => "new_test_pool",
59
+ :lb_method => "LB_METHOD_ROUND_ROBIN",
60
+ :members => [IControl::Common::IPPortDefinition.new(:address => "192.168.6.122",:port=>"4036")]
61
+ )
62
+ }.should raise_exception
63
+
64
+ end
65
+
66
+ end
67
+
68
+ describe "status_for method" do
69
+ it "should return the status of a given pool member given its address and port" do
70
+ status = @pool.status_for IControl::LocalLB::PoolMember.new(:address => "192.168.6.3",:port => "5050")
71
+ status.class.should be(Hash)
72
+ end
73
+
74
+ it "should return nil if the member is not found in the pool" do
75
+ status = @pool.status_for IControl::LocalLB::PoolMember.new(:address => "112.168.6.111",:port => "5050")
76
+ status.should be(nil)
77
+ end
78
+
79
+ end
80
+
81
+
82
+ describe "monitor_rule method" do
83
+ it "should return an instance of MonitorRule" do
84
+ monitor_rule = @pool.monitor_rule
85
+ monitor_rule.class.should be(IControl::LocalLB::MonitorRule)
86
+ end
87
+ end
88
+
89
+
90
+ describe "monitor_rule= method" do
91
+ it "should allow the assignment of a monitor rule to a pool" do
92
+ @monitor_rule_before = @pool.monitor_rule
93
+ monitor_rule = IControl::LocalLB::MonitorRule.new(:monitor_templates => ["tcp"])
94
+ @pool.monitor_rule = monitor_rule
95
+ @monitor_rule_after = @pool.monitor_rule
96
+ # A state should exists in the mock in order to make these tests
97
+ # @monitor_rule_after.monitor_templates.should_not == @monitor_rule_before.monitor_templates
98
+ end
99
+ end
100
+
101
+
102
+ describe "member method" do
103
+
104
+ it "should exists" do
105
+ @pool.member.should_not be(nil)
106
+ end
107
+
108
+ it "should return an array of PoolMembers" do
109
+ @pool.member.class.should be(Array)
110
+ @pool.member.first.class.should be(IControl::LocalLB::PoolMember)
111
+ end
112
+ end
113
+
114
+ describe "lb_method method" do
115
+ it "should return a String with a valid lb_method constant" do
116
+ @pool.lb_method.class.should be(String)
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,271 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe IControl::LocalLB::ProfileHttpClass do
4
+
5
+ before do
6
+ @profile = IControl::LocalLB::ProfileHttpClass.find("test_profile1")
7
+ @profile2 = IControl::LocalLB::ProfileHttpClass.find("test_profile2")
8
+ @arguments = {"host" => "test.com","cookie" => "test_cookie","header" => "test_header", "path" => "/test/path"}
9
+ end
10
+
11
+ describe "find method" do
12
+
13
+ it "should have a find class method called find" do
14
+ IControl::LocalLB::ProfileHttpClass.methods.should include(:find)
15
+ end
16
+
17
+ it "should return an array of IControl::LocalLB::ProfileHttpClass instances when find(:all) is called" do
18
+ profiles = IControl::LocalLB::ProfileHttpClass.find(:all)
19
+ profiles.class.should be(Array)
20
+ profiles[0].class.should be(IControl::LocalLB::ProfileHttpClass)
21
+ end
22
+
23
+ it "should return the first element when called with :first argument" do
24
+ @profile.class.should be(IControl::LocalLB::ProfileHttpClass)
25
+ end
26
+
27
+ end
28
+
29
+ describe "path_match_pattern" do
30
+
31
+ it "should allow retreive its associated path_match_patterns" do
32
+ @profile.path_match_pattern.class.should be(Array)
33
+ end
34
+
35
+
36
+ it "should allow retreive its associated path_match_patterns" do
37
+ @profile.host_match_pattern.class.should be(Array)
38
+ end
39
+ end
40
+
41
+
42
+ describe "base_profile? method" do
43
+
44
+ it "should return a boolean value" do
45
+ @profile.base_profile?.should be_equal(false)
46
+ end
47
+
48
+ end
49
+
50
+ describe "default_profile method" do
51
+
52
+ it "should exist" do
53
+ @profile.default_profile.should_not be_nil
54
+ end
55
+
56
+ it "should result another profile" do
57
+ @profile.default_profile.class.should be(IControl::LocalLB::ProfileHttpClass)
58
+ end
59
+
60
+ it "should return a base profile" do
61
+ @profile.default_profile.base_profile?.should be_equal(true)
62
+ end
63
+
64
+ end
65
+
66
+ ["host","cookie","header","path"].each do |type|
67
+
68
+ describe "#{type}_match_pattern method" do
69
+
70
+ it "should exist" do
71
+ @profile2.methods.should include("#{type}_match_pattern".to_sym)
72
+ end
73
+
74
+ it "should return an Array" do
75
+ @profile2.send("#{type}_match_pattern").class.should be(Array)
76
+ end
77
+
78
+ it "should not contents any nil value in the Array" do
79
+ @profile2.send("#{type}_match_pattern").should_not include(nil)
80
+ end
81
+
82
+ it "should return valid values" do
83
+ patterns = @profile2.send("#{type}_match_pattern")
84
+ patterns.length.should be_>(1)
85
+ patterns.first[:pattern].should_not be nil
86
+ end
87
+ end
88
+
89
+ describe "set_default_#{type}_match_pattern method" do
90
+
91
+ it "should exist" do
92
+ @profile2.methods.should include("set_default_#{type}_match_pattern".to_sym)
93
+ end
94
+
95
+ it "should return an empty array" do
96
+ value = @profile2.send("set_default_#{type}_match_pattern")
97
+ value.class.should be(Array)
98
+ end
99
+
100
+ it "should empty the contents of the array after called" do
101
+ register_conversation ["IControl.LocalLB.ProfileHttpClass_before_deletion.get_#{type}_match_pattern",
102
+ "IControl.LocalLB.ProfileHttpClass_after_deletion.get_#{type}_match_pattern"]
103
+ pattern = @profile.send"get_#{type}_match_pattern"
104
+ pattern.length.should_not be 0
105
+ pattern = @profile.send("set_default_#{type}_match_pattern")
106
+ pattern.length.should be 0
107
+ end
108
+ end
109
+
110
+ ["add","remove"].each do |op|
111
+
112
+ describe "#{op}_#{type}_host_match_pattern method" do
113
+
114
+ it "should exist" do
115
+ @profile2.methods.should include("#{op}_#{type}_match_pattern".to_sym)
116
+ end
117
+
118
+ it "sould return the recently created pattern if it correctly adds it" do
119
+ pattern = "test_#{type}"
120
+ result = @profile2.send("#{op}_#{type}_match_pattern",pattern,true)
121
+ result["pattern"].should ==(pattern)
122
+ result["is_glob"].should be(true)
123
+ end
124
+
125
+ it "sould allow the addition of string patterns as well" do
126
+ pattern = "test_#{type}-regexp"
127
+ result = @profile2.send("#{op}_#{type}_match_pattern",pattern)
128
+ result["pattern"].should ==(pattern)
129
+ result["is_glob"].should be(false)
130
+ end
131
+
132
+ it "should #{op} a new #{type} pattern" do
133
+ register_conversation ["IControl.LocalLB.ProfileHttpClass_before_#{op}.get_#{type}_match_pattern",
134
+ "IControl.LocalLB.ProfileHttpClass_after_#{op}.get_#{type}_match_pattern"]
135
+ match_pattern = @profile.send("#{type}_match_pattern")
136
+ case op
137
+ when "add" then
138
+ match_pattern.length.should be 0
139
+ when "remove" then
140
+ match_pattern.length.should > 0
141
+ match_pattern.first[:pattern].should ==@arguments[type]
142
+ end
143
+ lambda { @profile.send("#{op}_#{type}_match_pattern",@arguments[type])}.should_not raise_exception
144
+ match_pattern = @profile.send("#{type}_match_pattern")
145
+ case op
146
+ when "add" then
147
+ match_pattern.length.should_not be 0
148
+ match_pattern.first[:pattern].should ==@arguments[type]
149
+ when "remove" then
150
+ match_pattern.length.should be 0
151
+ end
152
+ end
153
+ end
154
+
155
+ end
156
+ end
157
+
158
+ describe "default_profile= method" do
159
+
160
+ it "should exist" do
161
+ @profile.methods.should include(:default_profile=)
162
+ end
163
+
164
+ it "should allow asignment of another profile " do
165
+ @profile.default_profile = IControl::LocalLB::ProfileHttpClass.find("anythingelse")
166
+ end
167
+
168
+ end
169
+
170
+ describe "pool method" do
171
+
172
+ it "should return a Pool instance or nil if none found" do
173
+
174
+ @profile.pool.should be(nil)
175
+
176
+ end
177
+
178
+ end
179
+
180
+
181
+ describe "pool assignment" do
182
+ it "should allow to assign a new pool overwriting the one before" do
183
+ first_pool = nil
184
+ first_pool = IControl::LocalLB::Pool.find("test_pool1")
185
+ before_pool = @profile.pool
186
+ before_pool.should be(nil)
187
+ after_pool = nil
188
+ after_pool = @profile.pool = first_pool
189
+ after_pool.class.should be(IControl::LocalLB::Pool)
190
+ end
191
+
192
+ it "should raise an exception when then pool does not exist" do
193
+ lambda{
194
+ @profile.pool = IControl::LocalLB::Pool.new(:id => "I-Dont-Exist")
195
+ }.should raise_exception
196
+ end
197
+ end
198
+
199
+ describe "rewrite_url method" do
200
+ it "should exist" do
201
+ @profile.methods.should include("rewrite_url".to_sym)
202
+ end
203
+
204
+ it "should return a hash containing the rewritting rule and the " do
205
+ rewrite_url = @profile2.rewrite_url
206
+ rewrite_url.class.should be(Hash)
207
+ rewrite_url[:rule].class.should be(String)
208
+ end
209
+ end
210
+
211
+ describe "unset_rewrite_url" do
212
+ it "should exist" do
213
+ @profile.methods.should include("unset_rewrite_url".to_sym)
214
+ end
215
+
216
+ it "should leave the field empty" do
217
+ @profile.unset_rewrite_url.should be(nil)
218
+ end
219
+
220
+ end
221
+
222
+ describe "set_rewrite_url method" do
223
+
224
+ it "should exist" do
225
+ @profile.methods.should include("set_rewrite_url".to_sym)
226
+ end
227
+
228
+ it "should allow the assignment of a new rewrite url" do
229
+ rewrite_url = @profile2.set_rewrite_url "/new_url_test"
230
+ rewrite_url[:rule].class.should be(String)
231
+ end
232
+
233
+ end
234
+
235
+ describe "redirect_location method" do
236
+ it "should exist" do
237
+ @profile.methods.should include("redirect_location".to_sym)
238
+ end
239
+
240
+ it "should return a hash containing the redirect_location " do
241
+ rewrite_url = @profile2.redirect_location
242
+ rewrite_url.class.should be(Hash)
243
+ rewrite_url[:rule].class.should be(String)
244
+ end
245
+ end
246
+
247
+
248
+ describe "set_redirect_location method" do
249
+
250
+ it "should exist" do
251
+ @profile.methods.should include("set_redirect_location".to_sym)
252
+ end
253
+
254
+ it "should allow the assignment of a new redirect_location" do
255
+ rewrite_url = @profile2.set_redirect_location "new_host"
256
+ rewrite_url[:rule].class.should be(String)
257
+ end
258
+
259
+ end
260
+
261
+ describe "create method" do
262
+ it "should exist" do
263
+ IControl::LocalLB::ProfileHttpClass.methods.should include(:create!)
264
+ end
265
+
266
+ it "should return the created Profile" do
267
+ IControl::LocalLB::ProfileHttpClass.create!("new_created_profile")
268
+ end
269
+ end
270
+
271
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe IControl::LocalLB::Rule do
4
+
5
+ before do
6
+ @rule = IControl::LocalLB::Rule.find(:first)
7
+ end
8
+
9
+ describe "find method" do
10
+
11
+ it "should have a find class method called find" do
12
+ IControl::LocalLB::Rule.methods.should include(:find)
13
+ end
14
+
15
+ it "should have retreive an object when find is call with id or nil it the object does not exists" do
16
+ IControl::LocalLB::Rule.find("irule_test").class.should be(IControl::LocalLB::Rule)
17
+ IControl::LocalLB::VirtualServer.find("unknown_rule").class.should_not be(IControl::LocalLB::Rule)
18
+ IControl::LocalLB::VirtualServer.find("unknown_rule").should be(nil)
19
+ end
20
+ end
21
+
22
+ end