add export specs

This commit is contained in:
David Dollar
2011-05-11 21:41:56 -04:00
parent 92c2b15785
commit 13fd1188ad
8 changed files with 70 additions and 0 deletions

View File

@@ -1,2 +1,21 @@
require "spec_helper"
require "foreman/export/upstart"
describe Foreman::Export::Upstart do
let(:engine) { Foreman::Engine.new(write_procfile) }
let(:upstart) { Foreman::Export::Upstart.new(engine) }
before(:each) { load_export_templates_into_fakefs("upstart") }
before(:each) { stub(upstart).say }
it "exports to the filesystem" do
upstart.export("/tmp/init")
File.read("/tmp/init/foreman.conf").should == example_export_file("upstart/foreman.conf")
File.read("/tmp/init/foreman-alpha.conf").should == example_export_file("upstart/foreman-alpha.conf")
File.read("/tmp/init/foreman-alpha-1.conf").should == example_export_file("upstart/foreman-alpha-1.conf")
File.read("/tmp/init/foreman-alpha-2.conf").should == example_export_file("upstart/foreman-alpha-2.conf")
File.read("/tmp/init/foreman-bravo.conf").should == example_export_file("upstart/foreman.bravo.conf")
File.read("/tmp/init/foreman-bravo-1.conf").should == example_export_file("upstart/foreman-bravo-1.conf")
end
end

View File

@@ -0,0 +1,6 @@
start on starting foreman-alpha
stop on stopping foreman-alpha
respawn
chdir /Users/david/Code/foreman
exec su foreman -c 'export PORT=5000; ./alpha >> /var/log/foreman/alpha-1.log 2>&1'

View File

@@ -0,0 +1,6 @@
start on starting foreman-alpha
stop on stopping foreman-alpha
respawn
chdir /Users/david/Code/foreman
exec su foreman -c 'export PORT=5001; ./alpha >> /var/log/foreman/alpha-2.log 2>&1'

View File

@@ -0,0 +1,2 @@
start on starting foreman
stop on stopping foreman

View File

@@ -0,0 +1,6 @@
start on starting foreman-bravo
stop on stopping foreman-bravo
respawn
chdir /Users/david/Code/foreman
exec su foreman -c 'export PORT=5100; ./bravo >> /var/log/foreman/bravo-1.log 2>&1'

View File

@@ -0,0 +1,2 @@
start on starting foreman
stop on stopping foreman

View File

@@ -0,0 +1,8 @@
pre-start script
bash << "EOF"
mkdir -p /var/log/foreman
chown -R foreman /var/log/foreman
EOF
end script

View File

@@ -29,6 +29,27 @@ def write_procfile(procfile="Procfile")
file.puts "alpha: ./alpha"
file.puts "bravo: ./bravo"
end
File.expand_path(procfile)
end
def load_export_templates_into_fakefs(type)
FakeFS.deactivate!
files = Dir[File.expand_path("../../data/export/#{type}/**", __FILE__)].inject({}) do |hash, file|
hash.update(file => File.read(file))
end
FakeFS.activate!
files.each do |filename, contents|
File.open(filename, "w") do |f|
f.puts contents
end
end
end
def example_export_file(filename)
FakeFS.deactivate!
data = File.read(File.expand_path("../resources/export/#{filename}", __FILE__))
FakeFS.activate!
data
end
Rspec.configure do |config|