more cli tests
This commit is contained in:
1 parent
53eb08be4f
commit
ffb7e9d6a5
5 files changed
+25
-25
No files matched your search
@@ -2,5 +2,7 @@ module Foreman
|
|||||||
|
|
||||||
VERSION = "0.0.1"
|
VERSION = "0.0.1"
|
||||||
|
|
||||||
|
class AppDoesNotExist < Exception; end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
+5
-1
@@ -29,7 +29,11 @@ class Foreman::CLI < Thor
|
|||||||
desc "scale APP PROCESS AMOUNT", "Change the concurrency of a given process type"
|
desc "scale APP PROCESS AMOUNT", "Change the concurrency of a given process type"
|
||||||
|
|
||||||
def scale(app, process, amount)
|
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
|
end
|
||||||
|
|
||||||
private ######################################################################
|
private ######################################################################
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Foreman::Configuration
|
|||||||
end
|
end
|
||||||
|
|
||||||
def scale(process, amount)
|
def scale(process, amount)
|
||||||
old_amount = processes[process]
|
old_amount = processes[process].to_i
|
||||||
processes[process] = amount.to_i
|
processes[process] = amount.to_i
|
||||||
amount = amount.to_i
|
amount = amount.to_i
|
||||||
|
|
||||||
@@ -43,6 +43,8 @@ private ######################################################################
|
|||||||
config["#{app}_processes"].split(" ").each do |process|
|
config["#{app}_processes"].split(" ").each do |process|
|
||||||
processes[process] = config["#{app}_#{process}"].to_i
|
processes[process] = config["#{app}_#{process}"].to_i
|
||||||
end
|
end
|
||||||
|
rescue Errno::ENOENT
|
||||||
|
raise Foreman::AppDoesNotExist
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(command)
|
def run(command)
|
||||||
|
|||||||
@@ -61,15 +61,26 @@ describe "Foreman::CLI" do
|
|||||||
|
|
||||||
describe "scale" do
|
describe "scale" do
|
||||||
describe "without an existing configuration" 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
|
end
|
||||||
|
|
||||||
describe "with an existing configuration" do
|
describe "with an existing configuration" do
|
||||||
before(:each) { write_foreman_config("testapp") }
|
before(:each) { write_foreman_config("testapp") }
|
||||||
|
|
||||||
it "scales the specified process" do
|
it "scales a process that exists" do
|
||||||
mock.instance_of(Foreman::Configuration).scale("testprocess", "2")
|
mock.instance_of(Foreman::Configuration).scale("alpha", "2")
|
||||||
subject.scale("testapp", "testprocess", "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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,19 +3,6 @@ require "rspec"
|
|||||||
|
|
||||||
$:.unshift "lib"
|
$:.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)
|
def mock_error(subject, message)
|
||||||
mock_exit do
|
mock_exit do
|
||||||
mock(subject).puts("ERROR: #{message}")
|
mock(subject).puts("ERROR: #{message}")
|
||||||
@@ -27,12 +14,6 @@ def mock_exit(&block)
|
|||||||
block.should raise_error(SystemExit)
|
block.should raise_error(SystemExit)
|
||||||
end
|
end
|
||||||
|
|
||||||
# def stub_engine
|
|
||||||
# engine = mock(Foreman::Engine)
|
|
||||||
# stub(Foreman::Engine).new { engine }
|
|
||||||
# engine
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
def write_foreman_config(app)
|
def write_foreman_config(app)
|
||||||
File.open("/etc/foreman/#{app}.conf", "w") do |file|
|
File.open("/etc/foreman/#{app}.conf", "w") do |file|
|
||||||
file.puts %{#{app}_processes="alpha bravo"}
|
file.puts %{#{app}_processes="alpha bravo"}
|
||||||
|
|||||||
Reference in new issue
Block a user