Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Run tests against ng environment

- Use cfoundry instead of vmc
  • Loading branch information...
commit 5bc5b892e49dcb6574605cfd3f551398936b42f2 1 parent a09390e
Bleicke and Maria Shaldibina authored
View
2  cfruntime-tests/Gemfile
@@ -2,5 +2,5 @@ source "http://rubygems.org"
gem "rake", "~> 0.9.2"
gem "rspec", "~> 2.13"
gem "ci_reporter", "~> 1.6.5"
-gem "vmc"
+gem "cfoundry", "~> 0.5.2"
gem "curb"
View
37 cfruntime-tests/Gemfile.lock
@@ -1,19 +1,21 @@
GEM
remote: http://rubygems.org/
specs:
- addressable (2.2.6)
- builder (3.0.0)
- ci_reporter (1.6.8)
+ builder (3.2.0)
+ cf-uaa-lib (1.3.7)
+ multi_json
+ cfoundry (0.5.2)
+ cf-uaa-lib (~> 1.3.3)
+ multi_json (~> 1.3)
+ multipart-post (~> 1.1)
+ rubyzip (~> 0.9)
+ ci_reporter (1.6.9)
builder (>= 2.1.2)
- curb (0.7.16)
+ curb (0.8.3)
diff-lcs (1.2.1)
- interact (0.3)
- json_pure (1.5.4)
- spruz (~> 0.2.8)
- mime-types (1.17.2)
- rake (0.9.2.2)
- rest-client (1.6.7)
- mime-types (>= 1.16)
+ multi_json (1.6.1)
+ multipart-post (1.2.0)
+ rake (0.9.6)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
@@ -22,23 +24,14 @@ GEM
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.0)
- rubyzip2 (2.0.2)
- spruz (0.2.13)
- terminal-table (1.4.4)
- vmc (0.3.14)
- addressable (~> 2.2.6)
- interact (~> 0.3.0)
- json_pure (~> 1.5.1)
- rest-client (>= 1.6.1, < 1.7.0)
- rubyzip2 (~> 2.0.1)
- terminal-table (~> 1.4.2)
+ rubyzip (0.9.9)
PLATFORMS
ruby
DEPENDENCIES
+ cfoundry (~> 0.5.2)
ci_reporter (~> 1.6.5)
curb
rake (~> 0.9.2)
rspec (~> 2.13)
- vmc
View
2  cfruntime-tests/spec/assets/amqp_service_bindings_by_name/app.rb
@@ -27,7 +27,7 @@
def write_to_rabbit(key, value)
EventMachine.run do
- connection = CFRuntime::AMQPClient.create_from_svc('test-cfruntime-svc-test-rabbit')
+ connection = CFRuntime::AMQPClient.create_from_svc('amqp-name-cfruntime-svc-test-rabbit')
channel = AMQP::Channel.new(connection)
queue = channel.queue(key, :auto_delete => true)
exchange = channel.default_exchange
View
12 cfruntime-tests/spec/assets/service_bindings_by_name/app.rb
@@ -107,33 +107,33 @@
end
def load_redis
- CFRuntime::RedisClient.create_from_svc('test-cfruntime-svc-test-redis')
+ CFRuntime::RedisClient.create_from_svc('test-name-cfruntime-svc-test-redis')
end
def load_mysql
- client = CFRuntime::Mysql2Client.create_from_svc('test-cfruntime-svc-test-mysql')
+ client = CFRuntime::Mysql2Client.create_from_svc('test-name-cfruntime-svc-test-mysql')
result = client.query("SELECT table_name FROM information_schema.tables WHERE table_name = 'data_values'");
client.query("Create table IF NOT EXISTS data_values ( id varchar(20), data_value varchar(20)); ") if result.count != 1
client
end
def load_mongo
- db = CFRuntime::MongoClient.create_from_svc('test-cfruntime-svc-test-mongo').db
+ db = CFRuntime::MongoClient.create_from_svc('test-name-cfruntime-svc-test-mongo').db
coll = db['data_values']
end
def load_postgresql
- client = CFRuntime::PGClient.create_from_svc('test-cfruntime-svc-test-postgresql')
+ client = CFRuntime::PGClient.create_from_svc('test-name-cfruntime-svc-test-postgresql')
client.query("create table data_values (id varchar(20), data_value varchar(20));") if client.query("select * from information_schema.tables where table_name = 'data_values';").first.nil?
client
end
def load_blob
- CFRuntime::AWSS3Client.create_from_svc('test-cfruntime-svc-test-blob')
+ CFRuntime::AWSS3Client.create_from_svc('test-name-cfruntime-svc-test-blob')
end
def rabbit_service
- CFRuntime::CarrotClient.create_from_svc('test-cfruntime-svc-test-rabbit')
+ CFRuntime::CarrotClient.create_from_svc('test-name-cfruntime-svc-test-rabbit')
end
def write_to_rabbit(key, value, client)
View
21 cfruntime-tests/spec/cloud_services_spec.rb
@@ -8,14 +8,16 @@
describe "connects an application to services by type" do
before(:all) do
login
+ delete_app
+ delete_services
deploy_app("service_bindings_by_type")
- TEST_SERVICES.each { |service_name| provision_service(service_name) }
+ TEST_SERVICES.each { |service_name| provision_service(service_name, "test-type") }
start_app
end
after(:all) do
- delete_services(all_my_services)
delete_app
+ delete_services
end
TEST_SERVICES.each do |service_name|
@@ -28,14 +30,15 @@
describe "connects an application to services by name" do
before(:all) do
login
+ delete_services
deploy_app("service_bindings_by_name")
- TEST_SERVICES.each { |service_name| provision_service(service_name) }
+ TEST_SERVICES.each { |service_name| provision_service(service_name, "test-name") }
start_app
end
after(:all) do
- delete_services(all_my_services)
delete_app
+ delete_services
end
TEST_SERVICES.each do |service_name|
@@ -50,14 +53,15 @@
describe "connects an application using AMQP to rabbit service by type" do
before do
login
+ delete_services
deploy_app("amqp_service_bindings_by_type")
- provision_service(:rabbitmq)
+ provision_service(:rabbitmq, "amqp-type")
start_app
end
after do
- delete_services(all_my_services)
delete_app
+ delete_services
end
it "connects to rabbitmq by type" do
@@ -70,13 +74,14 @@
describe "connects an application using AMQP to rabbit service by name" do
before do
login
+ delete_services
deploy_app("amqp_service_bindings_by_name")
- provision_service(:rabbitmq)
+ provision_service(:rabbitmq, "amqp-name")
start_app
end
after do
- delete_services(all_my_services)
+ delete_services
delete_app
end
View
201 cfruntime-tests/spec/spec_helper.rb
@@ -1,5 +1,4 @@
-require 'vmc'
-require 'cli'
+require 'cfoundry'
require 'curb'
module CFRuntimeTests
@@ -22,8 +21,9 @@ def deploy_app(app_dir, start=false)
def login
target_url = "http://#{target}"
puts "Running tests on #{target_url} on behalf of #{test_user}"
- @client = VMC::Client.new(target_url)
+ @client = CFoundry::Client.new(target_url)
@client.login(test_user, test_pwd)
+ select_org_and_space if v2?
end
def test_user
@@ -38,7 +38,15 @@ def target
ENV['VCAP_TARGET'] || "api.cloudfoundry.com"
end
- def domain
+ def organization
+ ENV['VCAP_ORG'] || raise("Provide organization name in VCAP_ORG")
+ end
+
+ def space
+ ENV['VCAP_SPACE'] || raise("Provide space name in VCAP_SPACE")
+ end
+
+ def domain_name
target.split(".")[1..-1].join(".")
end
@@ -47,85 +55,90 @@ def app_name
end
def app_uri
- "#{app_name}.#{domain}"
+ "#{app_name}.#{domain_name}"
+ end
+
+ def v2?
+ @client.is_a?(CFoundry::V2::Client)
+ end
+
+ def select_org_and_space
+ @client.current_organization = @client.organization_by_name(organization)
+ @client.current_space = @client.current_organization.space_by_name(space)
end
def system_services
login unless @client
- @system_services ||= @client.services_info
+ @system_services ||= @client.services
end
def service_available?(name)
- system_services.each do |_, services|
- services.each do |service_name, _|
- return true if service_name == name
- end
- end
- false
+ !!system_service(name)
+ end
+
+ def system_service(name)
+ system_services.find { |s| s.label == name.to_s && s.provider == "core" }
end
- def create_app(framework='sinatra', runtime='ruby18', instances=1, memory=64)
+ def create_app(framework='sinatra', runtime='ruby18', instances=1, memory=256)
delete_app
- manifest = {
- :name => "#{app_name}",
- :staging => {
- :framework => framework,
- :runtime => runtime
- },
- :resources=> {
- :memory => memory
- },
- :uris => [app_uri],
- :instances => "#{instances}",
- }
- response = @client.create_app(app_name, manifest)
- if response.first == 400
- puts "Creation of app #{app_name} failed"
+ @app = @client.app
+ @app.name = app_name
+ @app.space = @client.current_space if v2?
+ @app.total_instances = instances
+ @app.command = "bundle exec ruby app.rb -p $PORT"
+ @app.memory = memory
+
+ unless v2?
+ @app.framework = framework
+ @app.runtime = runtime
+ end
+
+ @app.create!
+ map_url
+ end
+
+ def map_url
+ if v2?
+ domain = @client.current_space.domain_by_name(domain_name)
+ route = @client.routes_by_host(app_name, :depth => 0).find do |r|
+ r.domain == domain
+ end
+ unless route
+ route = @client.route
+ route.host = app_name
+ route.domain = domain
+ route.space = @client.current_space
+ route.create!
+ end
+ @app.add_route(route)
+ else
+ @app.urls << app_uri
+ @app.update!
end
end
def delete_app
- @client.delete_app(app_name)
- rescue
- nil
- end
-
- def upload_app(app_dir)
- upload_file, file = "#{Dir.tmpdir}/#{app_name}.zip", nil
- FileUtils.rm_f(upload_file)
- explode_dir = "#{Dir.tmpdir}/.vmc_#{app_name}_files"
- FileUtils.rm_rf(explode_dir) # Make sure we didn't have anything left over..
- Dir.chdir(app_dir) do
- FileUtils.mkdir(explode_dir)
- files = Dir.glob('{*,.[^\.]*}')
- # Do not process .git files
- files.delete('.git') if files
- FileUtils.cp_r(files, explode_dir)
- unless VMC::Cli::ZipUtil.get_files_to_pack(explode_dir).empty?
- VMC::Cli::ZipUtil.pack(explode_dir, upload_file)
- file = File.open(upload_file, 'rb')
+ return unless @client
+ return unless @client.app_by_name(app_name)
+ app = @client.app_by_name(app_name)
+ if v2?
+ app.routes.each do |route|
+ route.delete!
end
- @client.upload_app(app_name, file)
end
- ensure
- # Cleanup if we created an exploded directory.
- FileUtils.rm_f(upload_file) if upload_file
- FileUtils.rm_rf(explode_dir) if explode_dir
+ app.delete!
+ end
+
+ def upload_app(app_path)
+ @app.upload(app_path)
end
def start_app
- app_manifest = get_app_status
- if app_manifest == nil
- raise "Application #{app_name} does not exist, app needs to be created."
- end
- if app_manifest[:state] == 'STARTED'
- return
- end
- app_manifest[:state] = 'STARTED'
- response = @client.update_app(app_name, app_manifest)
- raise "Problem starting application #{app_name}." if response.first != 200
- expected_health = 1.0
- health = poll_until_done(expected_health)
+ puts "Starting application (please wait)"
+ @app.start!
+ expected_health = "RUNNING"
+ health = poll_until_done
health.should == expected_health
end
@@ -146,32 +159,33 @@ def restart_app
start_app
end
- def poll_until_done(expected_health)
+ def poll_until_done
secs_til_timeout = 60
- health = nil
sleep_time = 1
- while secs_til_timeout > 0 && health != expected_health
+ while secs_til_timeout > 0 && !@app.healthy?
sleep sleep_time
secs_til_timeout = secs_til_timeout - sleep_time
- status = get_app_status
- runningInstances = status[:runningInstances] || 0
- health = runningInstances/status[:instances].to_f
end
- health
+ @app.health
end
def get_app_status
- @client.app_info(app_name)
- rescue
- nil
+ @app && @app.state
end
- def provision_service(service_name)
- return unless service_available?(service_name)
- label = "test-#{app_name}-#{SERVICE_NAMES[service_name]}"
- @client.create_service(service_name, label)
- service_manifest = service_manifest(service_name, label)
- attach_provisioned_service(service_manifest)
+ def provision_service(service_type, prefix)
+ return unless service_available?(service_type)
+ service_instance = @client.service_instance
+ service_instance.name = "#{prefix}-#{app_name}-#{SERVICE_NAMES[service_type]}"
+ if v2?
+ service_instance.space = @client.current_space
+ service_instance.service_plan = system_service(service_type).service_plans.first
+ else
+ service_instance.vendor = service_type
+ end
+ service_instance.create!
+ attach_provisioned_service(service_instance)
+ sleep 1 # Wait for service to start
end
def mysql_service_manifest
@@ -245,29 +259,16 @@ def service_manifest(service_name, name)
manifests[service_name].merge(:name => name)
end
- def attach_provisioned_service(service_manifest)
- app_manifest = get_app_status
- provisioned_services = app_manifest[:services] || []
-
- provisioned_services << service_manifest[:name]
- app_manifest[:services] = provisioned_services
- @client.update_app(app_name, app_manifest)
+ def attach_provisioned_service(service_instance)
+ @app.bind(service_instance)
end
- def all_my_services
- @client.services.map{ |service| service[:name] }
- end
-
- def delete_services(services)
- services.each do |service|
- delete_service service
+ def delete_services
+ @client.current_space.service_instances.each do |service|
+ service.delete!
end
- end
-
- def delete_service(service)
- @client.delete_service(service)
- rescue
- nil
+ rescue CFoundry::NotFound
+ # Service was already removed
end
def verify_service(service_name)
Please sign in to comment.
Something went wrong with that request. Please try again.