add export specs
This commit is contained in:
@@ -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
|
||||
|
||||
6
spec/resources/export/upstart/foreman-alpha-1.conf
Normal file
6
spec/resources/export/upstart/foreman-alpha-1.conf
Normal 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'
|
||||
6
spec/resources/export/upstart/foreman-alpha-2.conf
Normal file
6
spec/resources/export/upstart/foreman-alpha-2.conf
Normal 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'
|
||||
2
spec/resources/export/upstart/foreman-alpha.conf
Normal file
2
spec/resources/export/upstart/foreman-alpha.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
start on starting foreman
|
||||
stop on stopping foreman
|
||||
6
spec/resources/export/upstart/foreman-bravo-1.conf
Normal file
6
spec/resources/export/upstart/foreman-bravo-1.conf
Normal 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'
|
||||
2
spec/resources/export/upstart/foreman.bravo.conf
Normal file
2
spec/resources/export/upstart/foreman.bravo.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
start on starting foreman
|
||||
stop on stopping foreman
|
||||
8
spec/resources/export/upstart/foreman.conf
Normal file
8
spec/resources/export/upstart/foreman.conf
Normal file
@@ -0,0 +1,8 @@
|
||||
pre-start script
|
||||
|
||||
bash << "EOF"
|
||||
mkdir -p /var/log/foreman
|
||||
chown -R foreman /var/log/foreman
|
||||
EOF
|
||||
|
||||
end script
|
||||
@@ -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|
|
||||
|
||||
Reference in New Issue
Block a user