diff --git a/spec/foreman/export/upstart_spec.rb b/spec/foreman/export/upstart_spec.rb index 16a3323..7cacaa3 100644 --- a/spec/foreman/export/upstart_spec.rb +++ b/spec/foreman/export/upstart_spec.rb @@ -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 diff --git a/spec/resources/export/upstart/foreman-alpha-1.conf b/spec/resources/export/upstart/foreman-alpha-1.conf new file mode 100644 index 0000000..721f7fe --- /dev/null +++ b/spec/resources/export/upstart/foreman-alpha-1.conf @@ -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' diff --git a/spec/resources/export/upstart/foreman-alpha-2.conf b/spec/resources/export/upstart/foreman-alpha-2.conf new file mode 100644 index 0000000..576c3b4 --- /dev/null +++ b/spec/resources/export/upstart/foreman-alpha-2.conf @@ -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' diff --git a/spec/resources/export/upstart/foreman-alpha.conf b/spec/resources/export/upstart/foreman-alpha.conf new file mode 100644 index 0000000..dac499c --- /dev/null +++ b/spec/resources/export/upstart/foreman-alpha.conf @@ -0,0 +1,2 @@ +start on starting foreman +stop on stopping foreman diff --git a/spec/resources/export/upstart/foreman-bravo-1.conf b/spec/resources/export/upstart/foreman-bravo-1.conf new file mode 100644 index 0000000..4542dfc --- /dev/null +++ b/spec/resources/export/upstart/foreman-bravo-1.conf @@ -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' diff --git a/spec/resources/export/upstart/foreman.bravo.conf b/spec/resources/export/upstart/foreman.bravo.conf new file mode 100644 index 0000000..dac499c --- /dev/null +++ b/spec/resources/export/upstart/foreman.bravo.conf @@ -0,0 +1,2 @@ +start on starting foreman +stop on stopping foreman diff --git a/spec/resources/export/upstart/foreman.conf b/spec/resources/export/upstart/foreman.conf new file mode 100644 index 0000000..de12c5c --- /dev/null +++ b/spec/resources/export/upstart/foreman.conf @@ -0,0 +1,8 @@ +pre-start script + +bash << "EOF" + mkdir -p /var/log/foreman + chown -R foreman /var/log/foreman +EOF + +end script diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b666503..9fa0b6b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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|