foreman 0.46.0-mingw32 → 0.50.0-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/README.md +6 -0
  2. data/bin/foreman-runner +3 -7
  3. data/bin/taskman +8 -0
  4. data/data/example/Procfile +4 -3
  5. data/data/example/spawnee +14 -0
  6. data/data/example/spawner +7 -0
  7. data/data/export/bluepill/master.pill.erb +11 -10
  8. data/data/export/launchd/launchd.plist.erb +22 -0
  9. data/data/export/runit/log/run.erb +7 -0
  10. data/data/export/runit/run.erb +2 -2
  11. data/data/export/supervisord/app.conf.erb +12 -12
  12. data/data/export/upstart/master.conf.erb +2 -2
  13. data/data/export/upstart/process.conf.erb +3 -3
  14. data/lib/foreman.rb +4 -0
  15. data/lib/foreman/cli.rb +59 -23
  16. data/lib/foreman/engine.rb +233 -147
  17. data/lib/foreman/engine/cli.rb +105 -0
  18. data/lib/foreman/env.rb +27 -0
  19. data/lib/foreman/export.rb +2 -2
  20. data/lib/foreman/export/base.rb +107 -12
  21. data/lib/foreman/export/bluepill.rb +3 -17
  22. data/lib/foreman/export/inittab.rb +8 -11
  23. data/lib/foreman/export/launchd.rb +15 -0
  24. data/lib/foreman/export/runit.rb +14 -39
  25. data/lib/foreman/export/supervisord.rb +3 -13
  26. data/lib/foreman/export/upstart.rb +9 -27
  27. data/lib/foreman/process.rb +73 -67
  28. data/lib/foreman/procfile.rb +59 -25
  29. data/lib/foreman/version.rb +1 -1
  30. data/man/foreman.1 +5 -1
  31. data/spec/foreman/cli_spec.rb +46 -150
  32. data/spec/foreman/engine_spec.rb +47 -74
  33. data/spec/foreman/export/base_spec.rb +4 -7
  34. data/spec/foreman/export/bluepill_spec.rb +7 -6
  35. data/spec/foreman/export/inittab_spec.rb +7 -7
  36. data/spec/foreman/export/launchd_spec.rb +21 -0
  37. data/spec/foreman/export/runit_spec.rb +12 -17
  38. data/spec/foreman/export/supervisord_spec.rb +7 -56
  39. data/spec/foreman/export/upstart_spec.rb +22 -21
  40. data/spec/foreman/process_spec.rb +27 -110
  41. data/spec/foreman/procfile_spec.rb +26 -16
  42. data/spec/resources/Procfile +4 -0
  43. data/spec/resources/bin/echo +2 -0
  44. data/spec/resources/bin/env +2 -0
  45. data/spec/resources/bin/test +2 -0
  46. data/spec/resources/export/bluepill/app-concurrency.pill +6 -4
  47. data/spec/resources/export/bluepill/app.pill +6 -4
  48. data/spec/resources/export/launchd/launchd-a.default +22 -0
  49. data/spec/resources/export/launchd/launchd-b.default +22 -0
  50. data/spec/resources/export/runit/{app-alpha-1-log-run → app-alpha-1/log/run} +0 -0
  51. data/spec/resources/export/runit/{app-alpha-1-run → app-alpha-1/run} +0 -0
  52. data/spec/resources/export/runit/{app-alpha-2-log-run → app-alpha-2/log/run} +0 -0
  53. data/spec/resources/export/runit/{app-alpha-2-run → app-alpha-2/run} +0 -0
  54. data/spec/resources/export/runit/{app-bravo-1-log-run → app-bravo-1/log/run} +0 -0
  55. data/spec/resources/export/runit/{app-bravo-1-run → app-bravo-1/run} +0 -0
  56. data/spec/resources/export/supervisord/app-alpha-1.conf +24 -0
  57. data/spec/resources/export/supervisord/app-alpha-2.conf +4 -4
  58. data/spec/spec_helper.rb +57 -6
  59. metadata +29 -21
  60. data/data/export/runit/log_run.erb +0 -7
  61. data/lib/foreman/color.rb +0 -40
  62. data/lib/foreman/procfile_entry.rb +0 -26
  63. data/lib/foreman/utils.rb +0 -18
  64. data/spec/foreman/color_spec.rb +0 -31
  65. data/spec/foreman/procfile_entry_spec.rb +0 -13
  66. data/spec/resources/export/supervisord/app-env-with-comma.conf +0 -24
  67. data/spec/resources/export/supervisord/app-env.conf +0 -21
  68. data/spec/resources/export/supervisord/app.conf +0 -24
@@ -1,14 +1,25 @@
1
1
  require "spec_helper"
2
2
  require "foreman/engine"
3
3
 
4
- describe "Foreman::Engine", :fakefs do
5
- subject { Foreman::Engine.new("Procfile", {}) }
4
+ class Foreman::Engine::Tester < Foreman::Engine
5
+ attr_reader :buffer
6
6
 
7
- before do
8
- any_instance_of(Foreman::Engine) do |engine|
9
- stub(engine).proctitle
10
- stub(engine).termtitle
11
- end
7
+ def startup
8
+ @buffer = ""
9
+ end
10
+
11
+ def output(name, data)
12
+ @buffer += "#{name}: #{data}"
13
+ end
14
+
15
+ def shutdown
16
+ end
17
+ end
18
+
19
+ describe "Foreman::Engine", :fakefs do
20
+ subject do
21
+ write_procfile "Procfile"
22
+ Foreman::Engine::Tester.new.load_procfile("Procfile")
12
23
  end
13
24
 
14
25
  describe "initialize" do
@@ -16,65 +27,53 @@ describe "Foreman::Engine", :fakefs do
16
27
  before { write_procfile }
17
28
 
18
29
  it "reads the processes" do
19
- subject.procfile["alpha"].command.should == "./alpha"
20
- subject.procfile["bravo"].command.should == "./bravo"
30
+ subject.process("alpha").command.should == "./alpha"
31
+ subject.process("bravo").command.should == "./bravo"
21
32
  end
22
33
  end
23
34
  end
24
35
 
25
36
  describe "start" do
26
37
  it "forks the processes" do
27
- write_procfile
28
- mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./alpha", is_a(IO))
29
- mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./bravo", is_a(IO))
38
+ mock(subject.process("alpha")).run(anything)
39
+ mock(subject.process("bravo")).run(anything)
30
40
  mock(subject).watch_for_output
31
41
  mock(subject).watch_for_termination
32
42
  subject.start
33
43
  end
34
44
 
35
45
  it "handles concurrency" do
36
- write_procfile
37
- engine = Foreman::Engine.new("Procfile",:concurrency => "alpha=2")
38
- mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./alpha", is_a(IO)).twice
39
- mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./bravo", is_a(IO)).never
40
- mock(engine).watch_for_output
41
- mock(engine).watch_for_termination
42
- engine.start
46
+ subject.options[:formation] = "alpha=2"
47
+ mock(subject.process("alpha")).run(anything).twice
48
+ mock(subject.process("bravo")).run(anything).never
49
+ mock(subject).watch_for_output
50
+ mock(subject).watch_for_termination
51
+ subject.start
43
52
  end
44
53
  end
45
54
 
46
55
  describe "directories" do
47
56
  it "has the directory default relative to the Procfile" do
48
57
  write_procfile "/some/app/Procfile"
49
- engine = Foreman::Engine.new("/some/app/Procfile")
50
- engine.directory.should == "/some/app"
58
+ engine = Foreman::Engine.new.load_procfile("/some/app/Procfile")
59
+ engine.root.should == "/some/app"
51
60
  end
52
61
  end
53
62
 
54
63
  describe "environment" do
55
- before(:each) do
56
- write_procfile
57
- stub(Process).fork
58
- any_instance_of(Foreman::Engine) do |engine|
59
- stub(engine).info
60
- stub(engine).spawn_processes
61
- stub(engine).watch_for_termination
62
- end
63
- end
64
-
65
- it "should read if specified" do
64
+ it "should read env files" do
66
65
  File.open("/tmp/env", "w") { |f| f.puts("FOO=baz") }
67
- engine = Foreman::Engine.new("Procfile", :env => "/tmp/env")
68
- engine.environment.should == {"FOO"=>"baz"}
69
- engine.start
66
+ subject.load_env("/tmp/env")
67
+ subject.env["FOO"].should == "baz"
70
68
  end
71
69
 
72
70
  it "should read more than one if specified" do
73
71
  File.open("/tmp/env1", "w") { |f| f.puts("FOO=bar") }
74
72
  File.open("/tmp/env2", "w") { |f| f.puts("BAZ=qux") }
75
- engine = Foreman::Engine.new("Procfile", :env => "/tmp/env1,/tmp/env2")
76
- engine.environment.should == { "FOO"=>"bar", "BAZ"=>"qux" }
77
- engine.start
73
+ subject.load_env "/tmp/env1"
74
+ subject.load_env "/tmp/env2"
75
+ subject.env["FOO"].should == "bar"
76
+ subject.env["BAZ"].should == "qux"
78
77
  end
79
78
 
80
79
  it "should handle quoted values" do
@@ -84,48 +83,22 @@ describe "Foreman::Engine", :fakefs do
84
83
  f.puts "FRED='barney'"
85
84
  f.puts 'OTHER="escaped\"quote"'
86
85
  end
87
- engine = Foreman::Engine.new("Procfile", :env => "/tmp/env")
88
- engine.environment.should == { "FOO" => "bar", "BAZ" => "qux", "FRED" => "barney", "OTHER" => 'escaped"quote' }
86
+ subject.load_env "/tmp/env"
87
+ subject.env["FOO"].should == "bar"
88
+ subject.env["BAZ"].should == "qux"
89
+ subject.env["FRED"].should == "barney"
90
+ subject.env["OTHER"].should == 'escaped"quote'
89
91
  end
90
92
 
91
93
  it "should fail if specified and doesnt exist" do
92
- mock.instance_of(Foreman::Engine).error("No such file: /tmp/env")
93
- engine = Foreman::Engine.new("Procfile", :env => "/tmp/env")
94
+ lambda { subject.load_env "/tmp/env" }.should raise_error(Errno::ENOENT)
94
95
  end
95
96
 
96
- it "should read .env if none specified" do
97
- File.open(".env", "w") { |f| f.puts("FOO=qoo") }
98
- engine = Foreman::Engine.new("Procfile")
99
- engine.environment.should == {"FOO"=>"qoo"}
100
- engine.start
101
- end
102
-
103
- it "should be loaded relative to the Procfile" do
104
- FileUtils.mkdir_p "/some/app"
105
- File.open("/some/app/.env", "w") { |f| f.puts("FOO=qoo") }
106
- write_procfile "/some/app/Procfile"
107
- engine = Foreman::Engine.new("/some/app/Procfile")
108
- engine.environment.should == {"FOO"=>"qoo"}
109
- engine.start
97
+ it "should set port from .env if specified" do
98
+ File.open("/tmp/env", "w") { |f| f.puts("PORT=9000") }
99
+ subject.load_env "/tmp/env"
100
+ subject.send(:base_port).should == 9000
110
101
  end
111
102
  end
112
103
 
113
- describe "utf8" do
114
- before(:each) do
115
- File.open("Procfile", "w") do |file|
116
- file.puts "utf8: #{resource_path("bin/utf8")}"
117
- end
118
- end
119
-
120
- it "should spawn" do
121
- stub(subject).watch_for_output
122
- stub(subject).watch_for_termination
123
- subject.start
124
- Process.waitall
125
- mock(subject).info(/started with pid \d+/, "utf8.1", anything)
126
- mock(subject).info("\xff\x03\n", "utf8.1", anything)
127
- subject.send(:poll_readers)
128
- subject.send(:poll_readers)
129
- end
130
- end
131
104
  end
@@ -1,10 +1,11 @@
1
1
  require "spec_helper"
2
- require "foreman/export/base"
2
+ require "foreman/engine"
3
+ require "foreman/export"
3
4
 
4
- describe "Foreman::Export::Base" do
5
+ describe "Foreman::Export::Base", :fakefs do
5
6
  let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
6
7
  let(:location) { "/tmp/init" }
7
- let(:engine) { Foreman::Engine.new(procfile) }
8
+ let(:engine) { Foreman::Engine.new().load_procfile(procfile) }
8
9
  let(:subject) { Foreman::Export::Base.new(location, engine) }
9
10
 
10
11
  it "has a say method for displaying info" do
@@ -12,10 +13,6 @@ describe "Foreman::Export::Base" do
12
13
  subject.send(:say, "foo")
13
14
  end
14
15
 
15
- it "export needs to be overridden" do
16
- lambda { subject.export }.should raise_error("export method must be overridden")
17
- end
18
-
19
16
  it "raises errors as a Foreman::Export::Exception" do
20
17
  lambda { subject.send(:error, "foo") }.should raise_error(Foreman::Export::Exception, "foo")
21
18
  end
@@ -4,10 +4,11 @@ require "foreman/export/bluepill"
4
4
  require "tmpdir"
5
5
 
6
6
  describe Foreman::Export::Bluepill, :fakefs do
7
- let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
8
- let(:engine) { Foreman::Engine.new(procfile) }
9
- let(:options) { Hash.new }
10
- let(:bluepill) { Foreman::Export::Bluepill.new("/tmp/init", engine, options) }
7
+ let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
8
+ let(:formation) { nil }
9
+ let(:engine) { Foreman::Engine.new(:formation => formation).load_procfile(procfile) }
10
+ let(:options) { Hash.new }
11
+ let(:bluepill) { Foreman::Export::Bluepill.new("/tmp/init", engine, options) }
11
12
 
12
13
  before(:each) { load_export_templates_into_fakefs("bluepill") }
13
14
  before(:each) { stub(bluepill).say }
@@ -24,8 +25,8 @@ describe Foreman::Export::Bluepill, :fakefs do
24
25
  bluepill.export
25
26
  end
26
27
 
27
- context "with concurrency" do
28
- let(:options) { Hash[:concurrency => "alpha=2"] }
28
+ context "with a process formation" do
29
+ let(:formation) { "alpha=2" }
29
30
 
30
31
  it "exports to the filesystem with concurrency" do
31
32
  bluepill.export
@@ -4,12 +4,12 @@ require "foreman/export/inittab"
4
4
  require "tmpdir"
5
5
 
6
6
  describe Foreman::Export::Inittab, :fakefs do
7
- let(:location) { "/tmp/inittab" }
8
- let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
9
- let(:location) { "/tmp/inittab" }
10
- let(:engine) { Foreman::Engine.new(procfile) }
11
- let(:options) { Hash.new }
12
- let(:inittab) { Foreman::Export::Inittab.new(location, engine, options) }
7
+ let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
8
+ let(:location) { "/tmp/inittab" }
9
+ let(:formation) { nil }
10
+ let(:engine) { Foreman::Engine.new(:formation => formation).load_procfile(procfile) }
11
+ let(:options) { Hash.new }
12
+ let(:inittab) { Foreman::Export::Inittab.new(location, engine, options) }
13
13
 
14
14
  before(:each) { load_export_templates_into_fakefs("inittab") }
15
15
  before(:each) { stub(inittab).say }
@@ -29,7 +29,7 @@ describe Foreman::Export::Inittab, :fakefs do
29
29
  end
30
30
 
31
31
  context "with concurrency" do
32
- let(:options) { Hash[:concurrency => "alpha=2"] }
32
+ let(:formation) { "alpha=2" }
33
33
 
34
34
  it "exports to the filesystem with concurrency" do
35
35
  inittab.export
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+ require "foreman/engine"
3
+ require "foreman/export/launchd"
4
+ require "tmpdir"
5
+
6
+ describe Foreman::Export::Launchd, :fakefs do
7
+ let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
8
+ let(:options) { Hash.new }
9
+ let(:engine) { Foreman::Engine.new().load_procfile(procfile) }
10
+ let(:launchd) { Foreman::Export::Launchd.new("/tmp/init", engine, options) }
11
+
12
+ before(:each) { load_export_templates_into_fakefs("launchd") }
13
+ before(:each) { stub(launchd).say }
14
+
15
+ it "exports to the filesystem" do
16
+ launchd.export
17
+ File.read("/tmp/init/app-alpha-1.plist").should == example_export_file("launchd/launchd-a.default")
18
+ File.read("/tmp/init/app-bravo-1.plist").should == example_export_file("launchd/launchd-b.default")
19
+ end
20
+
21
+ end
@@ -5,33 +5,28 @@ require "tmpdir"
5
5
 
6
6
  describe Foreman::Export::Runit, :fakefs do
7
7
  let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile", 'bar=baz') }
8
- let(:engine) { Foreman::Engine.new(procfile) }
9
- let(:runit) { Foreman::Export::Runit.new('/tmp/init', engine, :concurrency => 'alpha=2,bravo=1') }
8
+ let(:engine) { Foreman::Engine.new(:formation => "alpha=2,bravo=1").load_procfile(procfile) }
9
+ let(:options) { Hash.new }
10
+ let(:runit) { Foreman::Export::Runit.new('/tmp/init', engine, options) }
10
11
 
11
12
  before(:each) { load_export_templates_into_fakefs("runit") }
12
13
  before(:each) { stub(runit).say }
13
14
  before(:each) { stub(FakeFS::FileUtils).chmod }
14
15
 
15
16
  it "exports to the filesystem" do
16
- FileUtils.mkdir_p('/tmp/init')
17
-
17
+ engine.env["BAR"] = "baz"
18
18
  runit.export
19
19
 
20
- File.read("/tmp/init/app-alpha-1/run").should == example_export_file('runit/app-alpha-1-run')
21
- File.read("/tmp/init/app-alpha-1/log/run").should ==
22
- example_export_file('runit/app-alpha-1-log-run')
20
+ File.read("/tmp/init/app-alpha-1/run").should == example_export_file('runit/app-alpha-1/run')
21
+ File.read("/tmp/init/app-alpha-1/log/run").should == example_export_file('runit/app-alpha-1/log/run')
23
22
  File.read("/tmp/init/app-alpha-1/env/PORT").should == "5000\n"
24
- File.read("/tmp/init/app-alpha-1/env/BAR").should == "baz\n"
25
-
26
- File.read("/tmp/init/app-alpha-2/run").should == example_export_file('runit/app-alpha-2-run')
27
- File.read("/tmp/init/app-alpha-2/log/run").should ==
28
- example_export_file('runit/app-alpha-2-log-run')
23
+ File.read("/tmp/init/app-alpha-1/env/BAR").should == "baz\n"
24
+ File.read("/tmp/init/app-alpha-2/run").should == example_export_file('runit/app-alpha-2/run')
25
+ File.read("/tmp/init/app-alpha-2/log/run").should == example_export_file('runit/app-alpha-2/log/run')
29
26
  File.read("/tmp/init/app-alpha-2/env/PORT").should == "5001\n"
30
- File.read("/tmp/init/app-alpha-2/env/BAR").should == "baz\n"
31
-
32
- File.read("/tmp/init/app-bravo-1/run").should == example_export_file('runit/app-bravo-1-run')
33
- File.read("/tmp/init/app-bravo-1/log/run").should ==
34
- example_export_file('runit/app-bravo-1-log-run')
27
+ File.read("/tmp/init/app-alpha-2/env/BAR").should == "baz\n"
28
+ File.read("/tmp/init/app-bravo-1/run").should == example_export_file('runit/app-bravo-1/run')
29
+ File.read("/tmp/init/app-bravo-1/log/run").should == example_export_file('runit/app-bravo-1/log/run')
35
30
  File.read("/tmp/init/app-bravo-1/env/PORT").should == "5100\n"
36
31
  end
37
32
 
@@ -4,18 +4,18 @@ require "foreman/export/supervisord"
4
4
  require "tmpdir"
5
5
 
6
6
  describe Foreman::Export::Supervisord, :fakefs do
7
- let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
8
- let(:engine) { Foreman::Engine.new(procfile) }
9
- let(:options) { Hash.new }
10
- let(:supervisord) { Foreman::Export::Supervisord.new("/tmp/init", engine, options) }
7
+ let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
8
+ let(:formation) { nil }
9
+ let(:engine) { Foreman::Engine.new(:formation => formation).load_procfile(procfile) }
10
+ let(:options) { Hash.new }
11
+ let(:supervisord) { Foreman::Export::Supervisord.new("/tmp/init", engine, options) }
11
12
 
12
13
  before(:each) { load_export_templates_into_fakefs("supervisord") }
13
14
  before(:each) { stub(supervisord).say }
14
15
 
15
16
  it "exports to the filesystem" do
16
17
  supervisord.export
17
-
18
- File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app.conf")
18
+ File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app-alpha-1.conf")
19
19
  end
20
20
 
21
21
  it "cleans up if exporting into an existing dir" do
@@ -25,7 +25,7 @@ describe Foreman::Export::Supervisord, :fakefs do
25
25
  end
26
26
 
27
27
  context "with concurrency" do
28
- let(:options) { Hash[:concurrency => "alpha=2"] }
28
+ let(:formation) { "alpha=2" }
29
29
 
30
30
  it "exports to the filesystem with concurrency" do
31
31
  supervisord.export
@@ -33,53 +33,4 @@ describe Foreman::Export::Supervisord, :fakefs do
33
33
  end
34
34
  end
35
35
 
36
- context "with alternate templates" do
37
- let(:template_root) { "/tmp/alternate" }
38
- let(:supervisord) { Foreman::Export::Supervisord.new("/tmp/init", engine, :template => template_root) }
39
-
40
- before do
41
- FileUtils.mkdir_p template_root
42
- File.open("#{template_root}/app.conf.erb", "w") { |f| f.puts "alternate_template" }
43
- end
44
-
45
- it "can export with alternate template files" do
46
- supervisord.export
47
- File.read("/tmp/init/app.conf").should == "alternate_template\n"
48
- end
49
- end
50
-
51
- context "with alternate templates from home dir" do
52
- let(:default_template_root) {File.expand_path("#{ENV['HOME']}/.foreman/templates")}
53
-
54
- before do
55
- ENV['_FOREMAN_SPEC_HOME'] = ENV['HOME']
56
- ENV['HOME'] = "/home/appuser"
57
- FileUtils.mkdir_p default_template_root
58
- File.open("#{default_template_root}/app.conf.erb", "w") { |f| f.puts "default_alternate_template" }
59
- end
60
-
61
- after do
62
- ENV['HOME'] = ENV.delete('_FOREMAN_SPEC_HOME')
63
- end
64
-
65
- it "can export with alternate template files" do
66
- supervisord.export
67
- File.read("/tmp/init/app.conf").should == "default_alternate_template\n"
68
- end
69
- end
70
-
71
- context "environment export" do
72
- it "correctly translates environment when exporting" do
73
- File.open("/tmp/supervisord_env", "w") { |f| f.puts("QUEUE=fastqueue,slowqueue\nVERBOSE=1") }
74
-
75
- engine = Foreman::Engine.new(procfile,:env => "/tmp/supervisord_env")
76
- supervisor = Foreman::Export::Supervisord.new("/tmp/init", engine, options)
77
- stub(supervisor).say
78
-
79
- supervisor.export
80
-
81
- File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app-env-with-comma.conf")
82
- end
83
- end
84
-
85
36
  end
@@ -4,10 +4,11 @@ require "foreman/export/upstart"
4
4
  require "tmpdir"
5
5
 
6
6
  describe Foreman::Export::Upstart, :fakefs do
7
- let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
8
- let(:engine) { Foreman::Engine.new(procfile) }
9
- let(:options) { Hash.new }
10
- let(:upstart) { Foreman::Export::Upstart.new("/tmp/init", engine, options) }
7
+ let(:procfile) { write_procfile("/tmp/app/Procfile") }
8
+ let(:formation) { nil }
9
+ let(:engine) { Foreman::Engine.new(:formation => formation).load_procfile(procfile) }
10
+ let(:options) { Hash.new }
11
+ let(:upstart) { Foreman::Export::Upstart.new("/tmp/init", engine, options) }
11
12
 
12
13
  before(:each) { load_export_templates_into_fakefs("upstart") }
13
14
  before(:each) { stub(upstart).say }
@@ -33,8 +34,15 @@ describe Foreman::Export::Upstart, :fakefs do
33
34
  upstart.export
34
35
  end
35
36
 
36
- context "with concurrency" do
37
- let(:options) { Hash[:concurrency => "alpha=2"] }
37
+ it "quotes and escapes environment variables" do
38
+ engine.env['KEY'] = 'd"\|d'
39
+ upstart.export
40
+ "foobarfoo".should include "bar"
41
+ File.read("/tmp/init/app-alpha-1.conf").should =~ /KEY="d\\"\\\\\\\|d/
42
+ end
43
+
44
+ context "with a formation" do
45
+ let(:formation) { "alpha=2" }
38
46
 
39
47
  it "exports to the filesystem with concurrency" do
40
48
  upstart.export
@@ -48,38 +56,31 @@ describe Foreman::Export::Upstart, :fakefs do
48
56
  end
49
57
 
50
58
  context "with alternate templates" do
51
- let(:template_root) { "/tmp/alternate" }
52
- let(:upstart) { Foreman::Export::Upstart.new("/tmp/init", engine, :template => template_root) }
59
+ let(:template) { "/tmp/alternate" }
60
+ let(:options) { { :app => "app", :template => template } }
53
61
 
54
62
  before do
55
- FileUtils.mkdir_p template_root
56
- File.open("#{template_root}/master.conf.erb", "w") { |f| f.puts "alternate_template" }
63
+ FileUtils.mkdir_p template
64
+ File.open("#{template}/master.conf.erb", "w") { |f| f.puts "alternate_template" }
57
65
  end
58
66
 
59
67
  it "can export with alternate template files" do
60
68
  upstart.export
61
-
62
69
  File.read("/tmp/init/app.conf").should == "alternate_template\n"
63
70
  end
64
71
  end
65
72
 
66
73
  context "with alternate templates from home dir" do
67
- let(:default_template_root) {File.expand_path("#{ENV['HOME']}/.foreman/templates")}
68
74
 
69
75
  before do
70
- ENV['_FOREMAN_SPEC_HOME'] = ENV['HOME']
71
- ENV['HOME'] = "/home/appuser"
72
- FileUtils.mkdir_p default_template_root
73
- File.open("#{default_template_root}/master.conf.erb", "w") { |f| f.puts "default_alternate_template" }
74
- end
75
-
76
- after do
77
- ENV['HOME'] = ENV.delete('_FOREMAN_SPEC_HOME')
76
+ FileUtils.mkdir_p File.expand_path("~/.foreman/templates/upstart")
77
+ File.open(File.expand_path("~/.foreman/templates/upstart/master.conf.erb"), "w") do |file|
78
+ file.puts "default_alternate_template"
79
+ end
78
80
  end
79
81
 
80
82
  it "can export with alternate template files" do
81
83
  upstart.export
82
-
83
84
  File.read("/tmp/init/app.conf").should == "default_alternate_template\n"
84
85
  end
85
86
  end