This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

add additional tests for war deployment and error handling to client

  • Loading branch information...
ryanbrainard committed Apr 11, 2012
1 parent 1c5d858 commit 91490d8218f9afd1992354532335a9a32545adcb
Showing with 69 additions and 16 deletions.
  1. +0 −2 Gemfile
  2. +1 −1 init.rb
  3. +17 −4 lib/heroku/command/deploy.rb
  4. +49 −8 spec/heroku/command/deploy_spec.rb
  5. +2 −1 spec/spec_helper.rb
View
@@ -4,6 +4,4 @@ gem "heroku"
group :test do
gem "rspec"
- gem "webmock"
- gem "fakefs", :git => "https://github.com/mmriis/fakefs.git", :branch => "chown_chmod"
end
View
@@ -1 +1 @@
-require "heroku/command/direct"
+require "heroku/command/deploy"
@@ -16,18 +16,26 @@ class Heroku::Command::Deploy < Heroku::Command::BaseWithApp
def war
war = extract_option("--war")
host = extract_option("--host")
+
if host == nil
host = "direct-to.herokuapp.com"
end
+
if war == nil
raise Heroku::Command::CommandFailed, "No .war specified.\nSpecify which war to use with --war <war file name>"
end
+
if !war.end_with?(".war")
raise Heroku::Command::CommandFailed, "War file must have a .war extension"
end
+
+ if !File.exists? war
+ raise Heroku::Command::CommandFailed, "War file not found"
+ end
+
display("Pushing #{war} to #{app}")
begin
- response = RestClient.post "http://:#{Heroku::Auth.api_key}@#{host}/direct/#{app}/war", :war => File.new(war, 'rb')
+ response = RestClient.post "http://:#{api_key}@#{host}/direct/#{app}/war", :war => File.new(war, 'rb')
display(json_decode(response)['status'])
monitor = response.headers[:location]
monitorHash = nil
@@ -45,13 +53,18 @@ def war
if status == "success"
display(monitorHash['message'] + " " + monitorHash['release'])
else
- display(monitorHash['message'])
+ raise(monitorHash['message'])
end
rescue Exception => e
- display("E" + e)
+ display("Error: " + e.message)
+ raise e
end
+ status
+ end
-
+ protected
+ def api_key
+ Heroku::Auth.api_key
end
end
@@ -2,25 +2,66 @@
describe Heroku::Command::Deploy do
+ before(:all) do
+ @app_name = ENV['HEROKU_TEST_APP_NAME']
+ end
+
+ before(:each) do
+ @war_file = Tempfile.new(["test", ".war"])
+ @war_file.close
+ end
+
+ after(:each) do
+ @war_file.unlink
+ end
+
+ context "when a war file and app is specified" do
+ #noinspection RubyArgCount
+ let(:deploy) { Heroku::Command::Deploy.new [], :app => @app_name, :war => @war_file.path }
+
+ it "the war should be deployed" do
+ result = deploy.war
+ result.should eql "success"
+ end
+ end
+
+ context "when heroku credentials are invalid" do
+ #noinspection RubyArgCount
+ let(:deploy) { Heroku::Command::Deploy.new [], :app => @app_name, :war => @war_file.path }
+
+ before do
+ deploy.stub(:api_key).and_return "something_invalid"
+ end
+
+ it "an error should be raised" do
+ lambda { deploy.war }.should raise_error(RuntimeError, /Unable to get user info/)
+ end
+ end
+
context "when no war file is specified" do
#noinspection RubyArgCount
- let(:deploy) { Heroku::Command::Deploy.new [], :app => "blahblahblah" }
+ let(:deploy) { Heroku::Command::Deploy.new [], :app => @app_name }
it "an error should be raised" do
- lambda do
- deploy.war
- end.should raise_error(Heroku::Command::CommandFailed, "No .war specified.\nSpecify which war to use with --war <war file name>")
+ lambda { deploy.war }.should raise_error(Heroku::Command::CommandFailed, "No .war specified.\nSpecify which war to use with --war <war file name>")
end
end
context "when a war file without a .war extension is specified" do
#noinspection RubyArgCount
- let(:deploy) { Heroku::Command::Deploy.new [], :app => "blahblahblah", :war => "something.notwar" }
+ let(:deploy) { Heroku::Command::Deploy.new [], :app => @app_name, :war => "something.notwar" }
+
+ it "an error should be raised" do
+ lambda { deploy.war }.should raise_error(Heroku::Command::CommandFailed, "War file must have a .war extension")
+ end
+ end
+
+ context "when a war file is specified but can't be found'" do
+ #noinspection RubyArgCount
+ let(:deploy) { Heroku::Command::Deploy.new [], :app => @app_name, :war => "not_there.war" }
it "an error should be raised" do
- lambda do
- deploy.war
- end.should raise_error(Heroku::Command::CommandFailed, "War file must have a .war extension")
+ lambda { deploy.war }.should raise_error(Heroku::Command::CommandFailed, "War file not found")
end
end
end
View
@@ -1,3 +1,4 @@
require "heroku/cli"
require "heroku/command/deploy"
-require "rspec"
+require "rspec"
+require "tempfile"

0 comments on commit 91490d8

Please sign in to comment.