Permalink
Browse files

unify ruby app specs into a single spec

  • Loading branch information...
1 parent 2e77ab6 commit 55dd0db3b7be7c7dc4e7250e0d35116b319babd2 Bleicke and Dmitriy Kalinin committed Mar 23, 2013
2 assets
View
@@ -57,21 +57,23 @@ env_test_app:
path: "assets/sinatra/env_test_app"
command: "bundle exec ruby env_test.rb -p $VCAP_APP_PORT"
-broken_app:
+# Ruby apps:
+ruby18:
memory: 512
- path: "assets/sinatra/broken_app"
- command: "bundle exec ruby broken.rb -p $VCAP_APP_PORT"
+ path: "assets/ruby/ruby18"
+ command: "bundle exec ruby main.rb -p $VCAP_APP_PORT"
-git_gems_app_ruby18:
+ruby19:
memory: 512
- path: "assets/sinatra/git_gems_app"
- command: "bundle exec ruby app.rb -p $VCAP_APP_PORT"
+ path: "assets/ruby/ruby19"
+ command: "bundle exec ruby main.rb -p $VCAP_APP_PORT"
-git_gems_app_ruby19:
+rails3:
memory: 512
- path: "assets/sinatra/git_gems_app"
- command: "bundle exec ruby app.rb -p $VCAP_APP_PORT"
+ path: "assets/ruby/rails3"
+ command: "bundle exec rake db:migrate --trace && bundle exec rails server thin -p $PORT"
+#-
sinatra_gem_groups:
memory: 512
path: "assets/sinatra/gem_groups"
@@ -87,11 +89,6 @@ broken_gem_app:
path: "assets/sinatra/broken_gem_app"
command: "bundle exec ruby main.rb -p $VCAP_APP_PORT"
-rails3_app:
- memory: 512
- path: "assets/rails3/rails3_app"
- command: "bundle exec rake db:migrate && bundle exec rails server thin -p $PORT"
-
jpa_app:
memory: 512
path: ".assets-binaries/jpa-guestbook.war"
View
@@ -94,7 +94,10 @@ def start(need_check = true, async = false, &blk)
unless @app.running?
@log.info "Start App: #{@app.name}"
begin
- @app.start!(true, &blk)
+ @app.start!(true) do |url|
+ puts "Pushing #{@app.name} - #{url}"
+ blk.call(url) if blk
+ end
rescue Exception => e
@log.error "Start App: #{@app.name} failed.\n#{e.to_s}"
raise RuntimeError, "Start App: #{@app.name} failed.\n#{e.to_s}\n#{@session.print_client_logs}"
@@ -7,45 +7,72 @@ module ScriptsHelper
# Service
def create_service(service_manifest, name=nil)
service_name = name || service_manifest[:vendor]
- require_namespace = name.nil?
- service = @session.service(service_name, require_namespace)
- unless service.available?(service_manifest)
- @session.log.debug("Service: (#{service_manifest[:vendor]} #{service_manifest[:version]}) " +
- "is not available on target: #{@session.TARGET}")
- pending("Service: (#{service_manifest[:vendor]} #{service_manifest[:version]}) " +
- "is not available on target: #{@session.TARGET}")
+
+ time_block "create_service '#{service_name}'" do
+ require_namespace = name.nil?
+ service = @session.service(service_name, require_namespace)
+
+ unless service.available?(service_manifest)
+ msg = <<-MSG
+ Service:
+ #{service_manifest[:vendor]}
+ #{service_manifest[:version]}
+ is not available on target: #{@session.TARGET}
+ MSG
+
+ @session.log.debug(msg)
+ pending(msg)
+ end
+
+ service.create(service_manifest)
+ service
end
- service.create(service_manifest)
- service
end
def bind_service(service_manifest, app, name=nil)
- service = create_service(service_manifest, name)
- app.bind(service)
- service
+ time_block "bind_service '#{app.name}'" do
+ service = create_service(service_manifest, name)
+ app.bind(service)
+ service
+ end
end
# Application
def create_app(app_name, prefix = '', domain=nil)
- app = @session.app(app_name, prefix, domain)
- app.load_manifest
- if app.manifest['path'].end_with?('.jar') || app.manifest['path'].end_with?('.war')
- pending "Package not found, please run update.sh" unless File.exist? app.manifest['path']
+ time_block "create_app '#{app_name}'" do
+ app = @session.app(app_name, prefix, domain)
+ app.load_manifest
+ if app.manifest['path'].end_with?('.jar') || app.manifest['path'].end_with?('.war')
+ pending "Package not found, please run update.sh" unless File.exist? app.manifest['path']
+ end
+ @current_app = app
+ app
end
- @current_app = app
- app
end
def create_push_app(app_name, prefix = '', domain=nil, services=[])
- app = create_app(app_name, prefix, domain)
- service_instances = services.map do |service|
- create_service(service)
- end
- app.push(service_instances)
- unless @session.v2?
- app.healthy?.should be_true, "Application #{app.name} is not running"
+ time_block "create_push_app '#{app_name}'" do
+ app = create_app(app_name, prefix, domain)
+
+ service_instances = services.map do |service|
+ create_service(service)
+ end
+
+ app.push(service_instances)
+
+ unless @session.v2?
+ app.healthy?.should be_true, "Application #{app.name} is not running"
+ end
+
+ app
end
- app
+ end
+
+ def time_block(name)
+ t = Time.new
+ result = yield
+ puts "Took %.5fs for #{name} to finish" % (Time.now - t)
+ result
end
end
end
View
@@ -90,15 +90,6 @@ def get_app_info(apps, appname)
crash.files("/app").should_not == nil
end
- it "get crash information for a broken application" do
- app = create_app("broken_app")
- app.push(nil, nil, false)
-
- crash = get_crashes(app.name).first
- crash.files("/").should_not == nil
- crash.files("/app").should_not == nil
- end
-
def get_crashes(name)
app = @client.app_by_name(name)
secs = VCAP_BVT_APP_ASSETS["timeout_secs"]
@@ -3,10 +3,7 @@
include BVT::Spec
describe "Simple::Lifecycle" do
-
- before(:all) do
- @session = BVT::Harness::CFSession.new
- end
+ before(:all) { @session = BVT::Harness::CFSession.new }
after(:each) do
show_crashlogs
@@ -33,5 +30,15 @@
@session.apps.length.should == len - 1
end
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ # reconsider how to tes
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ it "is able to run an app that does not bind to ports" do
+ app = create_push_app("standalone_simple_ruby_app")
+ app.logs =~ /running version/
+ end
end
-
@@ -1,65 +0,0 @@
-require "harness"
-require "spec_helper"
-include BVT::Spec
-
-describe "Simple::RubyGems" do
- before(:all) { @session = BVT::Harness::CFSession.new }
-
- after do
- show_crashlogs
- @session.cleanup!
- end
-
- def verify_service(service_manifest, app, key)
- data = "#{service_manifest[:vendor]}#{key}"
- url = SERVICE_URL_MAPPING[service_manifest[:vendor]]
- app.get_response(:post, "/service/#{url}/#{key}", data)
- app.get_response(:get, "/service/#{url}/#{key}").to_str.should == data
- end
-
- it "access my application root and see hello from sinatra" do
- app = create_push_app("broken_gem_app")
- app.stats.should_not == nil
- app.get_response(:get).should_not == nil
- app.get_response(:get).to_str.should_not == nil
- app.get_response(:get).to_str.should == "hello from sinatra"
- end
-
- it "sinatra test deploy app with git gems using ruby19" do
- app = create_push_app("git_gems_app_ruby19")
- app.stats.should_not == nil
- response = app.get_response(:get,"/")
- response.code.should == 200
- response.to_str.should == "hello from git"
- end
-
- it "sinatra test deploy app with git gems using ruby18" do
- app = create_push_app("git_gems_app_ruby18")
- app.stats.should_not == nil
- response = app.get_response(:get,"/")
- response.code.should == 200
- response.to_str.should == "hello from git"
- end
-
- it "sinatra test deploy app with Gemfile.lock containing Windows versions" do
- app = create_push_app("sinatra_windows_gemfile", nil, nil, [MYSQL_MANIFEST, POSTGRESQL_MANIFEST])
- staging_log = app.file("logs/staging_task.log")
- staging_log.should_not match "Installing yajl-ruby"
- staging_log.should include "Installing mysql2"
- staging_log.should include "Installing pg"
-
- verify_service(MYSQL_MANIFEST, app, "abc")
- verify_service(POSTGRESQL_MANIFEST, app, "abc")
- end
-
- it "sinatra test deploy app containing gems specifying a ruby platform" do
- app = create_push_app("sinatra_gem_groups")
- staging_log = app.file("logs/staging_task.log")
- staging_log.should include "Installing uglifier (1.2.6)"
- staging_log.should_not include "Installing yajl-ruby (0.8.3)"
-
- response = app.get_response(:get, "/")
- response.code.should == 200
- response.to_str.should == "hello from sinatra"
- end
-end
@@ -1,35 +0,0 @@
-require "harness"
-require "spec_helper"
-include BVT::Spec
-
-describe "Simple::RubyRails3" do
-
- before(:all) do
- @session = BVT::Harness::CFSession.new
- end
-
- after(:each) do
- show_crashlogs
- @session.cleanup!
- end
-
- it "access my application root and see it's running version" do
- @app = create_push_app("app_rails_version", nil, nil, [MYSQL_MANIFEST])
- @app.stats.should_not == nil
-
- @app.get_response(:get).should_not == nil
- @app.get_response(:get).to_str.should_not == nil
- @app.get_response(:get).to_str.should == "running version 1.9.2"
- end
-
- it "precompiles assets" do
- @app = create_push_app("rails_3_2_app")
- @app.stats.should_not == nil
- res = @app.get_response(:get, "/assets/manifest.yml")
- res.should_not == nil
- res.to_str.should match /application.js: application-\w/
- res = @app.get_response(:get, "/assets/application.js")
- res.to_str.should match /alert\(\"Hello from CoffeeScript!\"\)/
- end
-
-end
View
@@ -2,24 +2,71 @@
require "spec_helper"
include BVT::Spec
-describe "Simple::Ruby" do
+describe "Ruby" do
+ before(:all) { @session = BVT::Harness::CFSession.new }
- before(:all) do
- @session = BVT::Harness::CFSession.new
+ def self.with_app(app_asset_name)
+ before(:all) { @app = create_push_app(app_asset_name) }
+ after(:all) { @session.cleanup! }
+ define_method(:app) { @app }
end
- after(:each) do
- show_crashlogs
- @session.cleanup!
+ describe "ruby 1.8" do
+ with_app "ruby18"
+
+ it "starts the app successfully" do
+ res = app.get_response(:get, "/ruby_version")
+ res.to_str.should == "1.8.7"
+ end
+
+ it "supports git gems" do
+ app.file("logs/staging_task.log").tap do |log|
+ log.should match %r{Using cf .* git://github.com/cloudfoundry/cf.git}
+ end
+ end
+
+ it "installs 1.8 native extensions" do
+ app.file("logs/staging_task.log").tap do |log|
+ log.should include "Installing ffi"
+ end
+ end
end
- it "Simple ruby app" do
- app = create_push_app("standalone_ruby_app")
- app.get_response(:get).to_str.should == "running version 1.9.2"
+ describe "ruby 1.9" do
+ with_app "ruby19"
+
+ it "starts the app successfully" do
+ res = app.get_response(:get, "/ruby_version")
+ res.to_str.should start_with("1.9")
+ end
+
+ it "supports git gems" do
+ app.file("logs/staging_task.log").tap do |log|
+ log.should match %r{Using cf .* git://github.com/cloudfoundry/cf.git}
+ end
+ end
+
+ it "installs 1.9 native extensions" do
+ app.file("logs/staging_task.log").tap do |log|
+ log.should include "Installing ffi"
+ end
+ end
end
- it "Simple ruby app and no URL" do
- app = create_push_app("standalone_simple_ruby_app")
- app.logs =~ /running version 1.9.2/
+ describe "rails" do
+ with_app "rails3"
+
+ it "starts the app successfully" do
+ res = app.get_response(:get, "/health")
+ res.to_str.should == "ok"
+ end
end
+
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ # crashlogs
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!=
end

0 comments on commit 55dd0db

Please sign in to comment.