File: model_tests.rb

package info (click to toggle)
ruby-fog-aws 3.33.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,180 kB
  • sloc: ruby: 75,405; javascript: 14; makefile: 9; sh: 4
file content (235 lines) | stat: -rw-r--r-- 7,809 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
Shindo.tests('AWS::AutoScaling | model_tests', ['aws', 'auto_scaling']) do

  tests('success') do
    lc = nil
    lc_id = 'fog-model-lc'

    tests('configurations') do
      tests('getting a missing configuration') do
        returns(nil) { Fog::AWS[:auto_scaling].configurations.get('fog-no-such-lc') }
      end

      tests('create configuration') do
        lc = Fog::AWS[:auto_scaling].configurations.create(:id => lc_id, :image_id => 'ami-8c1fece5', :instance_type => 't1.micro')
        #tests("dns names is set").returns(true) { lc.dns_name.is_a?(String) }
        tests("created_at is set").returns(true) { Time === lc.created_at }
        #tests("policies is empty").returns([]) { lc.policies }
      end

      tests('all configurations') do
        lc_ids = Fog::AWS[:auto_scaling].configurations.all.map{|e| e.id}
        tests("contains lc").returns(true) { lc_ids.include? lc_id }
      end

      tests('get configuration') do
        lc2 = Fog::AWS[:auto_scaling].configurations.get(lc_id)
        tests('ids match').returns(lc_id) { lc2.id }
      end

      tests('creating a duplicate configuration') do
        raises(Fog::AWS::AutoScaling::IdentifierTaken) do
          Fog::AWS[:auto_scaling].configurations.create(:id => lc_id, :image_id => 'ami-8c1fece5', :instance_type => 't1.micro')
        end
      end
    end

    tests('groups') do
      tests('getting a missing group') do
        returns(nil) { Fog::AWS[:auto_scaling].groups.get('fog-no-such-asg') }
      end

      asg = nil
      asg_id = 'fog-model-asg'

      tests('create') do
        asg = Fog::AWS[:auto_scaling].groups.create(:id => asg_id, :availability_zones => ['us-east-1d'], :launch_configuration_name => lc_id)
        #tests("dns names is set").returns(true) { asg.dns_name.is_a?(String) }
        tests("created_at is set").returns(true) { Time === asg.created_at }
        #tests("policies is empty").returns([]) { asg.policies }
      end

      tests('all') do
        asg_ids = Fog::AWS[:auto_scaling].groups.all.map{|e| e.id}
        tests("contains asg").returns(true) { asg_ids.include? asg_id }
      end

      tests('get') do
        asg2 = Fog::AWS[:auto_scaling].groups.get(asg_id)
        tests('ids match').returns(asg_id) { asg2.id }
      end

      tests('suspend processes') do
        asg.suspend_processes()
        if Fog.mocking?
          tests('processes suspended').returns([]) { asg.suspended_processes }
        end
      end

      tests('resume processes') do
        asg.resume_processes()
        tests('no processes suspended').returns([]) { asg.suspended_processes }
      end

      tests('creating a duplicate group') do
        raises(Fog::AWS::AutoScaling::IdentifierTaken) do
          Fog::AWS[:auto_scaling].groups.create(:id => asg_id, :availability_zones => ['us-east-1d'], :launch_configuration_name => lc_id)
        end
      end

      tests('destroy group') do
        asg.destroy
        asg = nil
      end

      #tests('registering an invalid instance') do
      #  raises(Fog::AWS::AutoScaling::InvalidInstance) { asg.register_instances('i-00000000') }
      #end

      #tests('deregistering an invalid instance') do
      #  raises(Fog::AWS::AutoScaling::InvalidInstance) { asg.deregister_instances('i-00000000') }
      #end
    end

    tests('configurations') do
      tests('destroy configuration') do
        lc.destroy
        lc = nil
      end
    end

    #server = Fog::AWS[:compute].servers.create
    #tests('register instance') do
    #  begin
    #    elb.register_instances(server.id)
    #  rescue Fog::AWS::ELB::InvalidInstance
    #    # It may take a moment for a newly created instances to be visible to ELB requests
    #    raise if @retried_registered_instance
    #    @retried_registered_instance = true
    #    sleep 1
    #    retry
    #  end
    #
    #  returns([server.id]) { elb.instances }
    #end

    #tests('instance_health') do
    #  returns('OutOfService') do
    #    elb.instance_health.detect{|hash| hash['InstanceId'] == server.id}['State']
    #  end
    #
    #  returns([server.id]) { elb.instances_out_of_service }
    #end

    #tests('deregister instance') do
    #  elb.deregister_instances(server.id)
    #  returns([]) { elb.instances }
    #end
    #server.destroy

    #tests('disable_availability_zones') do
    #  elb.disable_availability_zones(%w{us-east-1c us-east-1d})
    #  returns(%w{us-east-1a us-east-1b}) { elb.availability_zones.sort }
    #end

    #tests('enable_availability_zones') do
    #  elb.enable_availability_zones(%w{us-east-1c us-east-1d})
    #  returns(%w{us-east-1a us-east-1b us-east-1c us-east-1d}) { elb.availability_zones.sort }
    #end

    #tests('default health check') do
    #  default_health_check = {
    #    "HealthyThreshold"=>10,
    #    "Timeout"=>5,
    #    "UnhealthyThreshold"=>2,
    #    "Interval"=>30,
    #    "Target"=>"TCP:80"
    #  }
    #  returns(default_health_check) { elb.health_check }
    #end

    #tests('configure_health_check') do
    #  new_health_check = {
    #    "HealthyThreshold"=>5,
    #    "Timeout"=>10,
    #    "UnhealthyThreshold"=>3,
    #    "Interval"=>15,
    #    "Target"=>"HTTP:80/index.html"
    #  }
    #  elb.configure_health_check(new_health_check)
    #  returns(new_health_check) { elb.health_check }
    #end

    #tests('listeners') do
    #  default_listener_description = [{"Listener"=>{"InstancePort"=>80, "Protocol"=>"HTTP", "LoadBalancerPort"=>80}, "PolicyNames"=>[]}]
    #  tests('default') do
    #    returns(1) { elb.listeners.size }
    #
    #    listener = elb.listeners.first
    #    returns([80,80,'HTTP', []]) { [listener.instance_port, listener.lb_port, listener.protocol, listener.policy_names] }
    #
    #  end
    #
    #  tests('#get') do
    #    returns(80) { elb.listeners.get(80).lb_port }
    #  end
    #
    #  tests('create') do
    #    new_listener = { 'InstancePort' => 443, 'LoadBalancerPort' => 443, 'Protocol' => 'TCP'}
    #    elb.listeners.create(:instance_port => 443, :lb_port => 443, :protocol => 'TCP')
    #    returns(2) { elb.listeners.size }
    #    returns(443) { elb.listeners.get(443).lb_port }
    #  end
    #
    #  tests('destroy') do
    #    elb.listeners.get(443).destroy
    #    returns(nil) { elb.listeners.get(443) }
    #  end
    #end

    #tests('policies') do
    #  app_policy_id = 'my-app-policy'
    #
    #  tests 'are empty' do
    #    returns([]) { elb.policies.to_a }
    #  end
    #
    #  tests('#all') do
    #    returns([]) { elb.policies.all.to_a }
    #  end
    #
    #  tests('create app policy') do
    #    elb.policies.create(:id => app_policy_id, :cookie => 'my-app-cookie', :cookie_stickiness => :app)
    #    returns(app_policy_id) { elb.policies.first.id }
    #  end
    #
    #  tests('get policy') do
    #    returns(app_policy_id) { elb.policies.get(app_policy_id).id }
    #  end
    #
    #  tests('destroy app policy') do
    #    elb.policies.first.destroy
    #    returns([]) { elb.policies.to_a }
    #  end
    #
    #  lb_policy_id = 'my-lb-policy'
    #  tests('create lb policy') do
    #    elb.policies.create(:id => lb_policy_id, :expiration => 600, :cookie_stickiness => :lb)
    #    returns(lb_policy_id) { elb.policies.first.id }
    #  end
    #
    #  tests('setting a listener policy') do
    #    elb.set_listener_policy(80, lb_policy_id)
    #    returns([lb_policy_id]) { elb.listeners.get(80).policy_names }
    #  end
    #
    #  tests('unsetting a listener policy') do
    #    elb.unset_listener_policy(80)
    #    returns([]) { elb.listeners.get(80).policy_names }
    #  end
    #
    #  tests('a malformed policy') do
    #    raises(ArgumentError) { elb.policies.create(:id => 'foo', :cookie_stickiness => 'invalid stickiness') }
    #  end
    #end
  end
end