foreman 0.47.0 → 0.48.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. data/bin/taskman +8 -0
  2. data/data/example/Procfile +4 -3
  3. data/data/example/spawnee +14 -0
  4. data/data/example/spawner +7 -0
  5. data/data/export/bluepill/master.pill.erb +10 -10
  6. data/data/export/launchd/launchd.plist.erb +3 -3
  7. data/data/export/runit/log/run.erb +7 -0
  8. data/data/export/runit/run.erb +2 -2
  9. data/data/export/supervisord/app.conf.erb +12 -12
  10. data/data/export/upstart/master.conf.erb +2 -2
  11. data/data/export/upstart/process.conf.erb +3 -3
  12. data/lib/foreman/cli.rb +49 -21
  13. data/lib/foreman/engine.rb +208 -148
  14. data/lib/foreman/engine/cli.rb +98 -0
  15. data/lib/foreman/env.rb +27 -0
  16. data/lib/foreman/export.rb +0 -1
  17. data/lib/foreman/export/base.rb +58 -35
  18. data/lib/foreman/export/bluepill.rb +3 -17
  19. data/lib/foreman/export/inittab.rb +8 -11
  20. data/lib/foreman/export/launchd.rb +4 -16
  21. data/lib/foreman/export/runit.rb +14 -39
  22. data/lib/foreman/export/supervisord.rb +3 -13
  23. data/lib/foreman/export/upstart.rb +9 -27
  24. data/lib/foreman/process.rb +56 -67
  25. data/lib/foreman/procfile.rb +59 -25
  26. data/lib/foreman/version.rb +1 -1
  27. data/man/foreman.1 +4 -0
  28. data/spec/foreman/cli_spec.rb +38 -152
  29. data/spec/foreman/engine_spec.rb +46 -80
  30. data/spec/foreman/export/base_spec.rb +4 -7
  31. data/spec/foreman/export/bluepill_spec.rb +7 -6
  32. data/spec/foreman/export/inittab_spec.rb +7 -7
  33. data/spec/foreman/export/launchd_spec.rb +4 -7
  34. data/spec/foreman/export/runit_spec.rb +12 -17
  35. data/spec/foreman/export/supervisord_spec.rb +7 -56
  36. data/spec/foreman/export/upstart_spec.rb +18 -23
  37. data/spec/foreman/process_spec.rb +27 -124
  38. data/spec/foreman/procfile_spec.rb +26 -16
  39. data/spec/resources/Procfile +4 -0
  40. data/spec/resources/bin/echo +2 -0
  41. data/spec/resources/bin/env +2 -0
  42. data/spec/resources/bin/test +2 -0
  43. data/spec/resources/export/bluepill/app-concurrency.pill +4 -4
  44. data/spec/resources/export/bluepill/app.pill +4 -4
  45. data/spec/resources/export/runit/{app-alpha-1-log-run → app-alpha-1/log/run} +0 -0
  46. data/spec/resources/export/runit/{app-alpha-1-run → app-alpha-1/run} +0 -0
  47. data/spec/resources/export/runit/{app-alpha-2-log-run → app-alpha-2/log/run} +0 -0
  48. data/spec/resources/export/runit/{app-alpha-2-run → app-alpha-2/run} +0 -0
  49. data/spec/resources/export/runit/{app-bravo-1-log-run → app-bravo-1/log/run} +0 -0
  50. data/spec/resources/export/runit/{app-bravo-1-run → app-bravo-1/run} +0 -0
  51. data/spec/resources/export/supervisord/app-alpha-1.conf +24 -0
  52. data/spec/resources/export/supervisord/app-alpha-2.conf +4 -4
  53. data/spec/spec_helper.rb +58 -6
  54. metadata +24 -22
  55. data/data/export/runit/log_run.erb +0 -7
  56. data/lib/foreman/color.rb +0 -40
  57. data/lib/foreman/procfile_entry.rb +0 -26
  58. data/lib/foreman/utils.rb +0 -18
  59. data/spec/foreman/color_spec.rb +0 -31
  60. data/spec/foreman/procfile_entry_spec.rb +0 -13
  61. data/spec/resources/export/supervisord/app-env-with-comma.conf +0 -24
  62. data/spec/resources/export/supervisord/app-env.conf +0 -21
  63. 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,55 +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
- end
95
-
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
94
+ lambda { subject.load_env "/tmp/env" }.should raise_error(Errno::ENOENT)
101
95
  end
102
96
 
103
97
  it "should set port from .env if specified" do
104
- File.open(".env", "w") { |f| f.puts("PORT=8017") }
105
- engine = Foreman::Engine.new("Procfile")
106
- engine.send(:base_port).should == "8017"
107
- engine.start
108
- end
109
-
110
- it "should be loaded relative to the Procfile" do
111
- FileUtils.mkdir_p "/some/app"
112
- File.open("/some/app/.env", "w") { |f| f.puts("FOO=qoo") }
113
- write_procfile "/some/app/Procfile"
114
- engine = Foreman::Engine.new("/some/app/Procfile")
115
- engine.environment.should == {"FOO"=>"qoo"}
116
- engine.start
98
+ File.open("/tmp/env", "w") { |f| f.puts("PORT=9000") }
99
+ subject.load_env "/tmp/env"
100
+ subject.send(:base_port).should == 9000
117
101
  end
118
102
  end
119
103
 
120
- describe "utf8" do
121
- before(:each) do
122
- File.open("Procfile", "w") do |file|
123
- file.puts "utf8: #{resource_path("bin/utf8")}"
124
- end
125
- end
126
-
127
- it "should spawn" do
128
- stub(subject).watch_for_output
129
- stub(subject).watch_for_termination
130
- subject.start
131
- Process.waitall
132
- mock(subject).info(/started with pid \d+/, "utf8.1", anything)
133
- mock(subject).info("\xff\x03\n", "utf8.1", anything)
134
- subject.send(:poll_readers)
135
- subject.send(:poll_readers)
136
- end
137
- end
138
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
@@ -5,20 +5,17 @@ require "tmpdir"
5
5
 
6
6
  describe Foreman::Export::Launchd, :fakefs do
7
7
  let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
8
- let(:engine) { Foreman::Engine.new(procfile) }
9
8
  let(:options) { Hash.new }
10
- let(:launchd) { Foreman::Export::Launchd.new("/tmp/init", engine, options) }
9
+ let(:engine) { Foreman::Engine.new().load_procfile(procfile) }
10
+ let(:launchd) { Foreman::Export::Launchd.new("/tmp/init", engine, options) }
11
11
 
12
12
  before(:each) { load_export_templates_into_fakefs("launchd") }
13
13
  before(:each) { stub(launchd).say }
14
14
 
15
15
  it "exports to the filesystem" do
16
16
  launchd.export
17
-
18
- normalize_space(File.read("/tmp/init/app-alpha-1.plist")).should == normalize_space(example_export_file("launchd/launchd-a.default"))
19
-
20
- normalize_space(File.read("/tmp/init/app-bravo-1.plist")).should == normalize_space(example_export_file("launchd/launchd-b.default"))
21
-
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")
22
19
  end
23
20
 
24
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 }
@@ -34,13 +35,14 @@ describe Foreman::Export::Upstart, :fakefs do
34
35
  end
35
36
 
36
37
  it "quotes and escapes environment variables" do
37
- engine.environment['KEY'] = 'd"\|d'
38
+ engine.env['KEY'] = 'd"\|d'
38
39
  upstart.export
39
- File.read("/tmp/init/app-alpha-1.conf").should include('KEY="d\"\\\\|d"')
40
+ "foobarfoo".should include "bar"
41
+ File.read("/tmp/init/app-alpha-1.conf").should =~ /KEY="d\\"\\\\\\\|d/
40
42
  end
41
43
 
42
- context "with concurrency" do
43
- let(:options) { Hash[:concurrency => "alpha=2"] }
44
+ context "with a formation" do
45
+ let(:formation) { "alpha=2" }
44
46
 
45
47
  it "exports to the filesystem with concurrency" do
46
48
  upstart.export
@@ -54,38 +56,31 @@ describe Foreman::Export::Upstart, :fakefs do
54
56
  end
55
57
 
56
58
  context "with alternate templates" do
57
- let(:template_root) { "/tmp/alternate" }
58
- let(:upstart) { Foreman::Export::Upstart.new("/tmp/init", engine, :template => template_root) }
59
+ let(:template) { "/tmp/alternate" }
60
+ let(:options) { { :app => "app", :template => template } }
59
61
 
60
62
  before do
61
- FileUtils.mkdir_p template_root
62
- 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" }
63
65
  end
64
66
 
65
67
  it "can export with alternate template files" do
66
68
  upstart.export
67
-
68
69
  File.read("/tmp/init/app.conf").should == "alternate_template\n"
69
70
  end
70
71
  end
71
72
 
72
73
  context "with alternate templates from home dir" do
73
- let(:default_template_root) {File.expand_path("#{ENV['HOME']}/.foreman/templates")}
74
74
 
75
75
  before do
76
- ENV['_FOREMAN_SPEC_HOME'] = ENV['HOME']
77
- ENV['HOME'] = "/home/appuser"
78
- FileUtils.mkdir_p default_template_root
79
- File.open("#{default_template_root}/master.conf.erb", "w") { |f| f.puts "default_alternate_template" }
80
- end
81
-
82
- after do
83
- 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
84
80
  end
85
81
 
86
82
  it "can export with alternate template files" do
87
83
  upstart.export
88
-
89
84
  File.read("/tmp/init/app.conf").should == "default_alternate_template\n"
90
85
  end
91
86
  end