more cli tests

This commit is contained in:
David Dollar
2010-05-20 00:14:59 -04:00
parent 53eb08be4f
commit ffb7e9d6a5
5 changed files with 26 additions and 26 deletions
+2
View File
@@ -2,5 +2,7 @@ module Foreman
VERSION = "0.0.1"
class AppDoesNotExist < Exception; end
end
+5 -1
View File
@@ -29,7 +29,11 @@ class Foreman::CLI < Thor
desc "scale APP PROCESS AMOUNT", "Change the concurrency of a given process type"
def scale(app, process, amount)
Foreman::Configuration.new(app).scale(process, amount)
config = Foreman::Configuration.new(app)
error "No such process: #{process}." unless config.processes[process]
config.scale(process, amount)
rescue Foreman::AppDoesNotExist
error "No such app: #{app}."
end
private ######################################################################
+3 -1
View File
@@ -12,7 +12,7 @@ class Foreman::Configuration
end
def scale(process, amount)
old_amount = processes[process]
old_amount = processes[process].to_i
processes[process] = amount.to_i
amount = amount.to_i
@@ -43,6 +43,8 @@ private ######################################################################
config["#{app}_processes"].split(" ").each do |process|
processes[process] = config["#{app}_#{process}"].to_i
end
rescue Errno::ENOENT
raise Foreman::AppDoesNotExist
end
def run(command)
+15 -4
View File
@@ -61,15 +61,26 @@ describe "Foreman::CLI" do
describe "scale" do
describe "without an existing configuration" do
# TODO
it "displays an error" do
mock_error(subject, "No such app: testapp.") do
subject.scale("testapp", "alpha", "2")
end
end
end
describe "with an existing configuration" do
before(:each) { write_foreman_config("testapp") }
it "scales the specified process" do
mock.instance_of(Foreman::Configuration).scale("testprocess", "2")
subject.scale("testapp", "testprocess", "2")
it "scales a process that exists" do
mock.instance_of(Foreman::Configuration).scale("alpha", "2")
subject.scale("testapp", "alpha", "2")
end
it "errors if a process that does not exist is specified" do
mock_error(subject, "No such process: invalidprocess.") do
dont_allow.instance_of(Foreman::Configuration).scale
subject.scale("testapp", "invalidprocess", "2")
end
end
end
end
+1 -20
View File
@@ -3,19 +3,6 @@ require "rspec"
$:.unshift "lib"
# def stub_configuration
# config = mock(Foreman::Configuration)
# Foreman::Configuration.stub(:new).and_return(config)
# config
# end
#
#
# def stub_export_upstart
# upstart = mock(Foreman::Export::Upstart)
# Foreman::Export::Upstart.stub(:new).and_return(upstart)
# upstart
# end
def mock_error(subject, message)
mock_exit do
mock(subject).puts("ERROR: #{message}")
@@ -27,17 +14,11 @@ def mock_exit(&block)
block.should raise_error(SystemExit)
end
# def stub_engine
# engine = mock(Foreman::Engine)
# stub(Foreman::Engine).new { engine }
# engine
# end
#
def write_foreman_config(app)
File.open("/etc/foreman/#{app}.conf", "w") do |file|
file.puts %{#{app}_processes="alpha bravo"}
file.puts %{#{app}_alpha="1"}
file.puts %{#{app}_bravo="2"}
file.puts %{#{app}_bravo="2"}
end
end