mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Unit tests for beanstalk
This commit is contained in:
parent
c1ec8a03b9
commit
cc3e9a0cf4
10 changed files with 560 additions and 0 deletions
5
tests/aws/models/beanstalk/application_tests.rb
Normal file
5
tests/aws/models/beanstalk/application_tests.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
Shindo.tests("Fog::AWS[:beanstalk] | application", ['aws', 'beanstalk']) do
|
||||
|
||||
model_tests(Fog::AWS[:beanstalk].applications, {:name => uniq_id('fog-test-app')}, false)
|
||||
|
||||
end
|
5
tests/aws/models/beanstalk/applications_tests.rb
Normal file
5
tests/aws/models/beanstalk/applications_tests.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
Shindo.tests("Fog::AWS[:beanstalk] | applications", ['aws', 'beanstalk']) do
|
||||
|
||||
collection_tests(Fog::AWS[:beanstalk].applications, {:name => uniq_id('fog-test-app')}, false)
|
||||
|
||||
end
|
131
tests/aws/models/beanstalk/environment_tests.rb
Normal file
131
tests/aws/models/beanstalk/environment_tests.rb
Normal file
|
@ -0,0 +1,131 @@
|
|||
Shindo.tests("Fog::AWS[:beanstalk] | environment", ['aws', 'beanstalk']) do
|
||||
|
||||
@beanstalk = Fog::AWS[:beanstalk]
|
||||
|
||||
@application_name = uniq_id('fog-test-app')
|
||||
@environment_name = uniq_id('fog-test-env')
|
||||
@version_names = []
|
||||
# Create two unique version names
|
||||
2.times {
|
||||
@version_names << uniq_id('fog-test-version')
|
||||
}
|
||||
|
||||
@application = @beanstalk.applications.create({:name => @application_name})
|
||||
|
||||
@versions = []
|
||||
@version_names.each { |name|
|
||||
@versions << @beanstalk.versions.create({
|
||||
:label => name,
|
||||
:application_name => @application_name,
|
||||
})
|
||||
}
|
||||
|
||||
@environment_opts = {
|
||||
:application_name => @application_name,
|
||||
:name => @environment_name,
|
||||
:version_label => @version_names[0],
|
||||
:solution_stack_name => '32bit Amazon Linux running Tomcat 7'
|
||||
}
|
||||
|
||||
# Note: These model tests can take quite a bit of time to run, about 10 minutes typically.
|
||||
model_tests(@beanstalk.environments, @environment_opts, false) do
|
||||
# Wait for initial ready before next tests.
|
||||
tests("#ready?").succeeds do
|
||||
@instance.wait_for { ready? }
|
||||
end
|
||||
|
||||
tests("#healthy?").succeeds do
|
||||
@instance.wait_for { healthy? }
|
||||
end
|
||||
|
||||
test("#events") do
|
||||
# There should be some events now.
|
||||
@instance.events.length > 0
|
||||
end
|
||||
|
||||
test("#version") do
|
||||
@instance.version.label == @version_names[0]
|
||||
end
|
||||
|
||||
test("#version= string") do
|
||||
# Set to version 2
|
||||
@instance.version = @version_names[1]
|
||||
|
||||
count = 0
|
||||
if @instance.version.label == @version_names[1]
|
||||
puts "new version names match"
|
||||
@instance.events.each { |event|
|
||||
if event.message == "Environment update is starting."
|
||||
count = count + 1
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
count == 1
|
||||
end
|
||||
|
||||
tests("#ready? after version= string").succeeds do
|
||||
@instance.wait_for { ready? }
|
||||
end
|
||||
|
||||
test("#version= version object") do
|
||||
# reset back to first version using version object
|
||||
@instance.version = @versions[0]
|
||||
|
||||
count = 0
|
||||
if @instance.version.label == @version_names[0]
|
||||
@instance.events.each { |event|
|
||||
if event.message == "Environment update is starting."
|
||||
count = count + 1
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
# Pass if we have two environment updating events
|
||||
count == 2
|
||||
end
|
||||
|
||||
tests("#ready? after version= version object").succeeds do
|
||||
@instance.wait_for { ready? }
|
||||
end
|
||||
|
||||
|
||||
test('#restart_app_server') do
|
||||
@instance.restart_app_server
|
||||
|
||||
passed = false
|
||||
@instance.events.each { |event|
|
||||
if event.message == "restartAppServer is starting."
|
||||
passed = true
|
||||
end
|
||||
}
|
||||
passed
|
||||
end
|
||||
|
||||
test('#rebuild') do
|
||||
@instance.rebuild
|
||||
passed = false
|
||||
@instance.events.each { |event|
|
||||
if event.message == "rebuildEnvironment is starting."
|
||||
passed = true
|
||||
end
|
||||
}
|
||||
passed
|
||||
end
|
||||
|
||||
# Wait for ready or next tests may fail
|
||||
tests("#ready? after rebuild").succeeds do
|
||||
@instance.wait_for { ready? }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Wait for instance to terminate before deleting application
|
||||
tests('#terminated?').succeeds do
|
||||
@instance.wait_for { terminated? }
|
||||
end
|
||||
|
||||
# delete application
|
||||
@application.destroy
|
||||
|
||||
end
|
32
tests/aws/models/beanstalk/environments_tests.rb
Normal file
32
tests/aws/models/beanstalk/environments_tests.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
Shindo.tests("Fog::AWS[:beanstalk] | environments", ['aws', 'beanstalk']) do
|
||||
|
||||
@beanstalk = Fog::AWS[:beanstalk]
|
||||
|
||||
@application_name = uniq_id('fog-test-app')
|
||||
@environment_name = uniq_id('fog-test-env')
|
||||
@version_name = uniq_id('fog-test-version')
|
||||
|
||||
# Create an application/version to use for testing.
|
||||
@version = @beanstalk.versions.create({
|
||||
:label => @version_name,
|
||||
:application_name => @application_name,
|
||||
:auto_create_application => true
|
||||
})
|
||||
|
||||
@application = @beanstalk.applications.get(@application_name)
|
||||
|
||||
@environment_opts = {
|
||||
:application_name => @application_name,
|
||||
:name => @environment_name,
|
||||
:version_label => @version_name,
|
||||
:solution_stack_name => '32bit Amazon Linux running Tomcat 7'
|
||||
}
|
||||
|
||||
collection_tests(@beanstalk.environments, @environment_opts, false)
|
||||
|
||||
# Wait for instance to terminate before deleting application
|
||||
@instance.wait_for { terminated? }
|
||||
# delete application
|
||||
@application.destroy
|
||||
|
||||
end
|
45
tests/aws/models/beanstalk/template_tests.rb
Normal file
45
tests/aws/models/beanstalk/template_tests.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
Shindo.tests("Fog::AWS[:beanstalk] | template", ['aws', 'beanstalk']) do
|
||||
|
||||
@beanstalk = Fog::AWS[:beanstalk]
|
||||
|
||||
@application_name = uniq_id('fog-test-app')
|
||||
@template_name = uniq_id('fog-test-template')
|
||||
|
||||
@template_description = 'A nice description'
|
||||
|
||||
@application = @beanstalk.applications.create({:name => @application_name})
|
||||
|
||||
@template_opts = {
|
||||
:application_name => @application_name,
|
||||
:name => @template_name,
|
||||
:description => @template_description,
|
||||
:solution_stack_name => '32bit Amazon Linux running Tomcat 7'
|
||||
}
|
||||
|
||||
model_tests(@beanstalk .templates, @template_opts, false) do
|
||||
|
||||
test("#attributes") do
|
||||
@instance.name == @template_name &&
|
||||
@instance.description == @template_description &&
|
||||
@instance.application_name == @application_name &&
|
||||
@instance.solution_stack_name == @template_opts[:solution_stack_name]
|
||||
end
|
||||
|
||||
test("#options") do
|
||||
options = @instance.options
|
||||
passed = false
|
||||
if options.each { |option|
|
||||
# See if we recognize at least one option
|
||||
if option["Name"] == 'LoadBalancerHTTPPort' && option["Namespace"] == 'aws:elb:loadbalancer'
|
||||
passed = true
|
||||
end
|
||||
}
|
||||
end
|
||||
passed
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# delete application
|
||||
@application.destroy
|
||||
end
|
60
tests/aws/models/beanstalk/templates_tests.rb
Normal file
60
tests/aws/models/beanstalk/templates_tests.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
Shindo.tests("Fog::AWS[:beanstalk] | templates", ['aws', 'beanstalk']) do
|
||||
|
||||
@beanstalk = Fog::AWS[:beanstalk]
|
||||
|
||||
@application_name = uniq_id('fog-test-app')
|
||||
@template_name = uniq_id('fog-test-template')
|
||||
|
||||
@template_description = 'A nice description'
|
||||
|
||||
@application = @beanstalk.applications.create({:name => @application_name})
|
||||
|
||||
params = {
|
||||
:application_name => @application_name,
|
||||
:name => @template_name,
|
||||
:description => @template_description,
|
||||
:solution_stack_name => '32bit Amazon Linux running Tomcat 7'
|
||||
}
|
||||
|
||||
collection = @beanstalk.templates
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#new(#{params.inspect})").succeeds do
|
||||
pending if Fog.mocking?
|
||||
collection.new(params)
|
||||
end
|
||||
|
||||
tests("#create(#{params.inspect})").succeeds do
|
||||
pending if Fog.mocking?
|
||||
@instance = collection.create(params)
|
||||
end
|
||||
|
||||
tests("#all").succeeds do
|
||||
pending if Fog.mocking?
|
||||
collection.all
|
||||
end
|
||||
|
||||
tests("#get(#{@application_name}, #{@template_name})").succeeds do
|
||||
pending if Fog.mocking?
|
||||
collection.get(@application_name, @template_name)
|
||||
end
|
||||
|
||||
if !Fog.mocking?
|
||||
@instance.destroy
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("#get(#{@application_name}, #{@template_name})").returns(nil) do
|
||||
pending if Fog.mocking?
|
||||
collection.get(@application_name, @template_name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# delete application
|
||||
@application.destroy
|
||||
|
||||
end
|
64
tests/aws/models/beanstalk/version_tests.rb
Normal file
64
tests/aws/models/beanstalk/version_tests.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
Shindo.tests("Fog::AWS[:beanstalk] | version", ['aws', 'beanstalk']) do
|
||||
|
||||
@beanstalk = Fog::AWS[:beanstalk]
|
||||
|
||||
@application_name = uniq_id('fog-test-app')
|
||||
@version_name = uniq_id('fog-test-version')
|
||||
|
||||
@version_description = 'A nice description'
|
||||
|
||||
@application = @beanstalk.applications.create({:name => @application_name})
|
||||
|
||||
@version_opts = {
|
||||
:application_name => @application_name,
|
||||
:label => @version_name,
|
||||
:description => @version_description
|
||||
}
|
||||
|
||||
model_tests(@beanstalk.versions, @version_opts, false) do
|
||||
|
||||
test("attributes") do
|
||||
@instance.label == @version_name &&
|
||||
@instance.description == @version_description &&
|
||||
@instance.application_name == @application_name
|
||||
end
|
||||
|
||||
test("#events") do
|
||||
# There should be some events now.
|
||||
@instance.events.length > 0
|
||||
end
|
||||
|
||||
test("#update description") do
|
||||
new_description = "A completely new description."
|
||||
@instance.description = new_description
|
||||
@instance.update
|
||||
|
||||
passed = false
|
||||
if @instance.description == new_description
|
||||
# reload version from AWS to verify save is committed to server, not just on local object
|
||||
if @beanstalk.versions.get(@application_name, @version_name).description == new_description
|
||||
passed = true
|
||||
end
|
||||
end
|
||||
passed
|
||||
end
|
||||
|
||||
test("#update description empty") do
|
||||
@instance.description = '' # Set to empty to nil out
|
||||
@instance.update
|
||||
|
||||
passed = false
|
||||
if @instance.description == nil
|
||||
# reload version from AWS to verify save is committed to server, not just on local object
|
||||
if @beanstalk.versions.get(@application_name, @version_name).description == nil
|
||||
passed = true
|
||||
end
|
||||
end
|
||||
passed
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# delete application
|
||||
@application.destroy
|
||||
end
|
59
tests/aws/models/beanstalk/versions_tests.rb
Normal file
59
tests/aws/models/beanstalk/versions_tests.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
Shindo.tests("Fog::AWS[:beanstalk] | versions", ['aws', 'beanstalk']) do
|
||||
|
||||
@beanstalk = Fog::AWS[:beanstalk]
|
||||
|
||||
@application_name = uniq_id('fog-test-app')
|
||||
@version_name = uniq_id('fog-test-version')
|
||||
|
||||
@version_description = 'A nice description'
|
||||
|
||||
@application = @beanstalk.applications.create({:name => @application_name})
|
||||
|
||||
params = {
|
||||
:application_name => @application_name,
|
||||
:label => @version_name,
|
||||
:description => @version_description
|
||||
}
|
||||
|
||||
collection = @beanstalk.versions
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#new(#{params.inspect})").succeeds do
|
||||
pending if Fog.mocking?
|
||||
collection.new(params)
|
||||
end
|
||||
|
||||
tests("#create(#{params.inspect})").succeeds do
|
||||
pending if Fog.mocking?
|
||||
@instance = collection.create(params)
|
||||
end
|
||||
|
||||
tests("#all").succeeds do
|
||||
pending if Fog.mocking?
|
||||
collection.all
|
||||
end
|
||||
|
||||
tests("#get(#{@application_name}, #{@version_name})").succeeds do
|
||||
pending if Fog.mocking?
|
||||
collection.get(@application_name, @version_name)
|
||||
end
|
||||
|
||||
if !Fog.mocking?
|
||||
@instance.destroy
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("#get(#{@application_name}, #{@version_name})").returns(nil) do
|
||||
pending if Fog.mocking?
|
||||
collection.get(@application_name, @version_name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
# delete application
|
||||
@application.destroy
|
||||
end
|
137
tests/aws/requests/beanstalk/application_tests.rb
Normal file
137
tests/aws/requests/beanstalk/application_tests.rb
Normal file
|
@ -0,0 +1,137 @@
|
|||
Shindo.tests('AWS::ElasticBeanstalk | application_tests', ['aws', 'beanstalk']) do
|
||||
|
||||
def unique_name(prefix)
|
||||
#get time (with 1/100th of sec accuracy)
|
||||
#want unique domain name and if provider is fast, this can be called more than once per second
|
||||
time = Time.now.to_i.to_s
|
||||
prefix + time
|
||||
end
|
||||
|
||||
@beanstalk = Fog::AWS[:beanstalk]
|
||||
@test_description = "A unique description."
|
||||
|
||||
@test_app_name = unique_name("fog-test-app-")
|
||||
|
||||
tests('success') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
@describe_applications_format = {
|
||||
'DescribeApplicationsResult' => {
|
||||
'Applications' => [
|
||||
'ApplicationName' => String,
|
||||
'ConfigurationTemplates' => [String],
|
||||
'Description' => Fog::Nullable::String,
|
||||
'DateCreated' => Time,
|
||||
'DateUpdated' => Time,
|
||||
'Versions' => [String]
|
||||
]},
|
||||
'ResponseMetadata' => {'RequestId'=> String},
|
||||
}
|
||||
|
||||
tests("#describe_applications format").formats(@describe_applications_format) do
|
||||
result = @beanstalk.describe_applications.body
|
||||
end
|
||||
|
||||
test("#create_application") {
|
||||
response = @beanstalk.create_application({
|
||||
'ApplicationName' => @test_app_name,
|
||||
'Description' => @test_description
|
||||
})
|
||||
|
||||
result = false
|
||||
if response.status == 200
|
||||
|
||||
app_info = response.body['CreateApplicationResult']['Application']
|
||||
if app_info
|
||||
if app_info['ApplicationName'] == @test_app_name &&
|
||||
app_info['Description'] == @test_description &&
|
||||
app_info['ConfigurationTemplates'].empty? &&
|
||||
app_info['Versions'].empty?
|
||||
result = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
test("#describe_applications all") {
|
||||
response = @beanstalk.describe_applications
|
||||
|
||||
result = false
|
||||
if response.status == 200
|
||||
apps = response.body['DescribeApplicationsResult']['Applications']
|
||||
apps.each { |app_info|
|
||||
if app_info
|
||||
if app_info['ApplicationName'] == @test_app_name &&
|
||||
app_info['Description'] == @test_description &&
|
||||
app_info['ConfigurationTemplates'].empty? &&
|
||||
app_info['Versions'].empty?
|
||||
result = true
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
test("#create_application filter") {
|
||||
# Test for a specific app
|
||||
response = @beanstalk.describe_applications([@test_app_name])
|
||||
|
||||
result = false
|
||||
if response.status == 200
|
||||
apps = response.body['DescribeApplicationsResult']['Applications']
|
||||
if apps && apps.length == 1
|
||||
app_info = apps.first
|
||||
if app_info['ApplicationName'] == @test_app_name &&
|
||||
app_info['Description'] == @test_description &&
|
||||
app_info['ConfigurationTemplates'].empty? &&
|
||||
app_info['Versions'].empty?
|
||||
result = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
test("#update_application description") {
|
||||
|
||||
@test_description = "A completely new description."
|
||||
|
||||
response = @beanstalk.update_application({
|
||||
'ApplicationName' => @test_app_name,
|
||||
'Description' => @test_description
|
||||
})
|
||||
|
||||
result = false
|
||||
if response.status == 200
|
||||
app_info = response.body['UpdateApplicationResult']['Application']
|
||||
if app_info
|
||||
if app_info['ApplicationName'] == @test_app_name &&
|
||||
app_info['Description'] == @test_description &&
|
||||
app_info['ConfigurationTemplates'].empty? &&
|
||||
app_info['Versions'].empty?
|
||||
result = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
test("#delete_application") {
|
||||
response = @beanstalk.delete_application(@test_app_name)
|
||||
|
||||
result = false
|
||||
if response.status == 200
|
||||
result = true
|
||||
end
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
end
|
||||
end
|
22
tests/aws/requests/beanstalk/solution_stack_tests.rb
Normal file
22
tests/aws/requests/beanstalk/solution_stack_tests.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
Shindo.tests('AWS::ElasticBeanstalk | solution_stack_tests', ['aws', 'beanstalk']) do
|
||||
|
||||
tests('success') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
@solution_stack_result_format = {
|
||||
'ListAvailableSolutionStacksResult' => {
|
||||
'SolutionStackDetails' => [
|
||||
'SolutionStackName' => String,
|
||||
'PermittedFileTypes' => [String]
|
||||
],
|
||||
'SolutionStacks' => [String]
|
||||
},
|
||||
'ResponseMetadata' => {'RequestId'=> String},
|
||||
}
|
||||
tests("#list_available_solution_stacks").formats(@solution_stack_result_format) do
|
||||
Fog::AWS[:beanstalk].list_available_solution_stacks.body
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue