overman 0.0.1 → 0.88.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -0
- data/bin/foreman-runner +41 -0
- data/bin/overman +7 -0
- data/data/example/Procfile +4 -0
- data/data/example/Procfile.without_colon +2 -0
- data/data/example/error +7 -0
- data/data/example/log/neverdie.log +4 -0
- data/data/example/spawnee +14 -0
- data/data/example/spawner +7 -0
- data/data/example/ticker +14 -0
- data/data/example/utf8 +11 -0
- data/data/export/bluepill/master.pill.erb +28 -0
- data/data/export/daemon/master.conf.erb +14 -0
- data/data/export/daemon/process.conf.erb +8 -0
- data/data/export/daemon/process_master.conf.erb +2 -0
- data/data/export/launchd/launchd.plist.erb +33 -0
- data/data/export/runit/log/run.erb +7 -0
- data/data/export/runit/run.erb +4 -0
- data/data/export/supervisord/app.conf.erb +31 -0
- data/data/export/systemd/master.target.erb +5 -0
- data/data/export/systemd/process.service.erb +21 -0
- data/data/export/upstart/master.conf.erb +2 -0
- data/data/export/upstart/process.conf.erb +15 -0
- data/data/export/upstart/process_master.conf.erb +2 -0
- data/lib/foreman/cli.rb +167 -0
- data/lib/foreman/distribution.rb +9 -0
- data/lib/foreman/engine/cli.rb +105 -0
- data/lib/foreman/engine.rb +494 -0
- data/lib/foreman/env.rb +29 -0
- data/lib/foreman/export/base.rb +170 -0
- data/lib/foreman/export/bluepill.rb +12 -0
- data/lib/foreman/export/daemon.rb +28 -0
- data/lib/foreman/export/inittab.rb +42 -0
- data/lib/foreman/export/launchd.rb +22 -0
- data/lib/foreman/export/runit.rb +34 -0
- data/lib/foreman/export/supervisord.rb +16 -0
- data/lib/foreman/export/systemd.rb +34 -0
- data/lib/foreman/export/upstart.rb +46 -0
- data/lib/foreman/export.rb +36 -0
- data/lib/foreman/helpers.rb +45 -0
- data/lib/foreman/process.rb +81 -0
- data/lib/foreman/procfile.rb +100 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/create_file.rb +103 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/create_link.rb +59 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/directory.rb +118 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/empty_directory.rb +135 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/file_manipulation.rb +327 -0
- data/lib/foreman/vendor/thor/lib/thor/actions/inject_into_file.rb +103 -0
- data/lib/foreman/vendor/thor/lib/thor/actions.rb +318 -0
- data/lib/foreman/vendor/thor/lib/thor/base.rb +656 -0
- data/lib/foreman/vendor/thor/lib/thor/command.rb +133 -0
- data/lib/foreman/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +85 -0
- data/lib/foreman/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/foreman/vendor/thor/lib/thor/core_ext/ordered_hash.rb +129 -0
- data/lib/foreman/vendor/thor/lib/thor/error.rb +32 -0
- data/lib/foreman/vendor/thor/lib/thor/group.rb +281 -0
- data/lib/foreman/vendor/thor/lib/thor/invocation.rb +177 -0
- data/lib/foreman/vendor/thor/lib/thor/line_editor/basic.rb +35 -0
- data/lib/foreman/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
- data/lib/foreman/vendor/thor/lib/thor/line_editor.rb +17 -0
- data/lib/foreman/vendor/thor/lib/thor/parser/argument.rb +70 -0
- data/lib/foreman/vendor/thor/lib/thor/parser/arguments.rb +175 -0
- data/lib/foreman/vendor/thor/lib/thor/parser/option.rb +146 -0
- data/lib/foreman/vendor/thor/lib/thor/parser/options.rb +220 -0
- data/lib/foreman/vendor/thor/lib/thor/parser.rb +4 -0
- data/lib/foreman/vendor/thor/lib/thor/rake_compat.rb +71 -0
- data/lib/foreman/vendor/thor/lib/thor/runner.rb +322 -0
- data/lib/foreman/vendor/thor/lib/thor/shell/basic.rb +436 -0
- data/lib/foreman/vendor/thor/lib/thor/shell/color.rb +149 -0
- data/lib/foreman/vendor/thor/lib/thor/shell/html.rb +126 -0
- data/lib/foreman/vendor/thor/lib/thor/shell.rb +81 -0
- data/lib/foreman/vendor/thor/lib/thor/util.rb +268 -0
- data/lib/foreman/vendor/thor/lib/thor/version.rb +3 -0
- data/lib/foreman/vendor/thor/lib/thor.rb +492 -0
- data/lib/foreman/version.rb +5 -0
- data/lib/foreman.rb +17 -0
- data/man/overman.1 +181 -0
- data/spec/foreman/cli_spec.rb +111 -0
- data/spec/foreman/engine_spec.rb +114 -0
- data/spec/foreman/export/base_spec.rb +19 -0
- data/spec/foreman/export/bluepill_spec.rb +37 -0
- data/spec/foreman/export/daemon_spec.rb +97 -0
- data/spec/foreman/export/inittab_spec.rb +40 -0
- data/spec/foreman/export/launchd_spec.rb +31 -0
- data/spec/foreman/export/runit_spec.rb +36 -0
- data/spec/foreman/export/supervisord_spec.rb +38 -0
- data/spec/foreman/export/systemd_spec.rb +155 -0
- data/spec/foreman/export/upstart_spec.rb +118 -0
- data/spec/foreman/export_spec.rb +24 -0
- data/spec/foreman/helpers_spec.rb +26 -0
- data/spec/foreman/process_spec.rb +70 -0
- data/spec/foreman/procfile_spec.rb +65 -0
- data/spec/foreman_spec.rb +16 -0
- data/spec/helper_spec.rb +19 -0
- data/spec/resources/Procfile +5 -0
- data/spec/resources/Procfile.bad +2 -0
- data/spec/resources/bin/echo +2 -0
- data/spec/resources/bin/env +2 -0
- data/spec/resources/bin/test +2 -0
- data/spec/resources/bin/utf8 +2 -0
- data/spec/resources/export/bluepill/app-concurrency.pill +49 -0
- data/spec/resources/export/bluepill/app.pill +81 -0
- data/spec/resources/export/daemon/app-alpha-1.conf +7 -0
- data/spec/resources/export/daemon/app-alpha-2.conf +7 -0
- data/spec/resources/export/daemon/app-alpha.conf +2 -0
- data/spec/resources/export/daemon/app-bravo-1.conf +7 -0
- data/spec/resources/export/daemon/app-bravo.conf +2 -0
- data/spec/resources/export/daemon/app.conf +14 -0
- data/spec/resources/export/inittab/inittab.concurrency +4 -0
- data/spec/resources/export/inittab/inittab.default +6 -0
- data/spec/resources/export/launchd/launchd-a.default +29 -0
- data/spec/resources/export/launchd/launchd-b.default +29 -0
- data/spec/resources/export/launchd/launchd-c.default +30 -0
- data/spec/resources/export/runit/app-alpha-1/log/run +7 -0
- data/spec/resources/export/runit/app-alpha-1/run +4 -0
- data/spec/resources/export/runit/app-alpha-2/log/run +7 -0
- data/spec/resources/export/runit/app-alpha-2/run +4 -0
- data/spec/resources/export/runit/app-bravo-1/log/run +7 -0
- data/spec/resources/export/runit/app-bravo-1/run +4 -0
- data/spec/resources/export/supervisord/app-alpha-1.conf +42 -0
- data/spec/resources/export/supervisord/app-alpha-2.conf +22 -0
- data/spec/resources/export/systemd/app-alpha.1.service +18 -0
- data/spec/resources/export/systemd/app-alpha.2.service +18 -0
- data/spec/resources/export/systemd/app-alpha.target +2 -0
- data/spec/resources/export/systemd/app-bravo.1.service +18 -0
- data/spec/resources/export/systemd/app-bravo.target +2 -0
- data/spec/resources/export/systemd/app.target +5 -0
- data/spec/resources/export/upstart/app-alpha-1.conf +11 -0
- data/spec/resources/export/upstart/app-alpha-2.conf +11 -0
- data/spec/resources/export/upstart/app-alpha.conf +2 -0
- data/spec/resources/export/upstart/app-bravo-1.conf +11 -0
- data/spec/resources/export/upstart/app-bravo.conf +2 -0
- data/spec/resources/export/upstart/app.conf +2 -0
- data/spec/spec_helper.rb +190 -0
- metadata +144 -16
- data/lib/overman/version.rb +0 -5
- data/lib/overman.rb +0 -1
@@ -0,0 +1,111 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "foreman/cli"
|
3
|
+
|
4
|
+
describe "Foreman::CLI", :fakefs do
|
5
|
+
subject { Foreman::CLI.new }
|
6
|
+
|
7
|
+
describe ".foreman" do
|
8
|
+
before { File.open(".foreman", "w") { |f| f.puts "formation: alpha=2" } }
|
9
|
+
|
10
|
+
it "provides default options" do
|
11
|
+
expect(subject.send(:options)["formation"]).to eq("alpha=2")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "is overridden by options at the cli" do
|
15
|
+
subject = Foreman::CLI.new([], :formation => "alpha=3")
|
16
|
+
expect(subject.send(:options)["formation"]).to eq("alpha=3")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "start" do
|
21
|
+
describe "when a Procfile doesnt exist", :fakefs do
|
22
|
+
it "displays an error" do
|
23
|
+
mock_error(subject, "Procfile does not exist.") do
|
24
|
+
expect_any_instance_of(Foreman::Engine).to_not receive(:start)
|
25
|
+
subject.start
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "with a valid Procfile" do
|
31
|
+
it "can run a single command" do
|
32
|
+
without_fakefs do
|
33
|
+
output = foreman("start env -f #{resource_path("Procfile")}")
|
34
|
+
expect(output).to match(/env.1/)
|
35
|
+
expect(output).not_to match(/test.1/)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can run all commands" do
|
40
|
+
without_fakefs do
|
41
|
+
output = foreman("start -f #{resource_path("Procfile")} -e #{resource_path(".env")}")
|
42
|
+
expect(output).to match(/echo.1 \| echoing/)
|
43
|
+
expect(output).to match(/env.1 \| bar/)
|
44
|
+
expect(output).to match(/test.1 \| testing/)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "sets PS variable with the process name" do
|
49
|
+
without_fakefs do
|
50
|
+
output = foreman("start -f #{resource_path("Procfile")}")
|
51
|
+
expect(output).to match(/ps.1 \| PS env var is ps.1/)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "fails if process fails" do
|
56
|
+
output = `bundle exec foreman start -f #{resource_path "Procfile.bad"} && echo success`
|
57
|
+
expect(output).not_to include 'success'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "check" do
|
63
|
+
it "with a valid Procfile displays the jobs" do
|
64
|
+
write_procfile
|
65
|
+
expect(foreman("check")).to eq("valid procfile detected (alpha, bravo, foo_bar, foo-bar)\n")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "with a blank Procfile displays an error" do
|
69
|
+
FileUtils.touch "Procfile"
|
70
|
+
expect(foreman("check")).to eq("ERROR: no processes defined\n")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "without a Procfile displays an error" do
|
74
|
+
expect(foreman("check")).to eq("ERROR: Procfile does not exist.\n")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "run" do
|
79
|
+
it "can run a command" do
|
80
|
+
expect(forked_foreman("run -f #{resource_path("Procfile")} echo 1")).to eq("1\n")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "doesn't parse options for the command" do
|
84
|
+
expect(forked_foreman("run -f #{resource_path("Procfile")} grep -e FOO #{resource_path(".env")}")).to eq("FOO=bar\n")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "includes the environment" do
|
88
|
+
expect(forked_foreman("run -f #{resource_path("Procfile")} -e #{resource_path(".env")} #{resource_path("bin/env FOO")}")).to eq("bar\n")
|
89
|
+
end
|
90
|
+
|
91
|
+
it "can run a command from the Procfile" do
|
92
|
+
expect(forked_foreman("run -f #{resource_path("Procfile")} test")).to eq("testing\n")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "exits with the same exit code as the command" do
|
96
|
+
expect(fork_and_get_exitstatus("run -f #{resource_path("Procfile")} echo 1")).to eq(0)
|
97
|
+
expect(fork_and_get_exitstatus("run -f #{resource_path("Procfile")} date 'invalid_date'")).to eq(1)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "version" do
|
102
|
+
it "displays gem version" do
|
103
|
+
expect(foreman("version").chomp).to eq(Foreman::VERSION)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "displays gem version on shortcut command" do
|
107
|
+
expect(foreman("-v").chomp).to eq(Foreman::VERSION)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "foreman/engine"
|
3
|
+
|
4
|
+
class Foreman::Engine::Tester < Foreman::Engine
|
5
|
+
attr_reader :buffer
|
6
|
+
|
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")
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "initialize" do
|
26
|
+
describe "with a Procfile" do
|
27
|
+
before { write_procfile }
|
28
|
+
|
29
|
+
it "reads the processes" do
|
30
|
+
expect(subject.process("alpha").command).to eq("./alpha")
|
31
|
+
expect(subject.process("bravo").command).to eq("./bravo")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "start" do
|
37
|
+
it "forks the processes" do
|
38
|
+
expect(subject.process("alpha")).to receive(:run)
|
39
|
+
expect(subject.process("bravo")).to receive(:run)
|
40
|
+
expect(subject).to receive(:watch_for_output)
|
41
|
+
expect(subject).to receive(:wait_for_shutdown_or_child_termination)
|
42
|
+
subject.start
|
43
|
+
end
|
44
|
+
|
45
|
+
it "handles concurrency" do
|
46
|
+
subject.options[:formation] = "alpha=2"
|
47
|
+
expect(subject.process("alpha")).to receive(:run).twice
|
48
|
+
expect(subject.process("bravo")).to_not receive(:run)
|
49
|
+
expect(subject).to receive(:watch_for_output)
|
50
|
+
expect(subject).to receive(:wait_for_shutdown_or_child_termination)
|
51
|
+
subject.start
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "directories" do
|
56
|
+
it "has the directory default relative to the Procfile" do
|
57
|
+
write_procfile "/some/app/Procfile"
|
58
|
+
engine = Foreman::Engine.new.load_procfile("/some/app/Procfile")
|
59
|
+
expect(engine.root).to eq("/some/app")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "environment" do
|
64
|
+
it "should read env files" do
|
65
|
+
write_file("/tmp/env") { |f| f.puts("FOO=baz") }
|
66
|
+
subject.load_env("/tmp/env")
|
67
|
+
expect(subject.env["FOO"]).to eq("baz")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should read more than one if specified" do
|
71
|
+
write_file("/tmp/env1") { |f| f.puts("FOO=bar") }
|
72
|
+
write_file("/tmp/env2") { |f| f.puts("BAZ=qux") }
|
73
|
+
subject.load_env "/tmp/env1"
|
74
|
+
subject.load_env "/tmp/env2"
|
75
|
+
expect(subject.env["FOO"]).to eq("bar")
|
76
|
+
expect(subject.env["BAZ"]).to eq("qux")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should handle quoted values" do
|
80
|
+
write_file("/tmp/env") do |f|
|
81
|
+
f.puts 'FOO=bar'
|
82
|
+
f.puts 'BAZ="qux"'
|
83
|
+
f.puts "FRED='barney'"
|
84
|
+
f.puts 'OTHER="escaped\"quote"'
|
85
|
+
f.puts 'URL="http://example.com/api?foo=bar&baz=1"'
|
86
|
+
end
|
87
|
+
subject.load_env "/tmp/env"
|
88
|
+
expect(subject.env["FOO"]).to eq("bar")
|
89
|
+
expect(subject.env["BAZ"]).to eq("qux")
|
90
|
+
expect(subject.env["FRED"]).to eq("barney")
|
91
|
+
expect(subject.env["OTHER"]).to eq('escaped"quote')
|
92
|
+
expect(subject.env["URL"]).to eq("http://example.com/api?foo=bar&baz=1")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should handle multiline strings" do
|
96
|
+
write_file("/tmp/env") do |f|
|
97
|
+
f.puts 'FOO="bar\nbaz"'
|
98
|
+
end
|
99
|
+
subject.load_env "/tmp/env"
|
100
|
+
expect(subject.env["FOO"]).to eq("bar\nbaz")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should fail if specified and doesnt exist" do
|
104
|
+
expect { subject.load_env "/tmp/env" }.to raise_error(Errno::ENOENT)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should set port from .env if specified" do
|
108
|
+
write_file("/tmp/env") { |f| f.puts("PORT=9000") }
|
109
|
+
subject.load_env "/tmp/env"
|
110
|
+
expect(subject.send(:base_port)).to eq(9000)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "foreman/engine"
|
3
|
+
require "foreman/export"
|
4
|
+
|
5
|
+
describe "Foreman::Export::Base", :fakefs do
|
6
|
+
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
|
7
|
+
let(:location) { "/tmp/init" }
|
8
|
+
let(:engine) { Foreman::Engine.new().load_procfile(procfile) }
|
9
|
+
let(:subject) { Foreman::Export::Base.new(location, engine) }
|
10
|
+
|
11
|
+
it "has a say method for displaying info" do
|
12
|
+
expect(subject).to receive(:puts).with("[foreman export] foo")
|
13
|
+
subject.send(:say, "foo")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "raises errors as a Foreman::Export::Exception" do
|
17
|
+
expect { subject.send(:error, "foo") }.to raise_error(Foreman::Export::Exception, "foo")
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "foreman/engine"
|
3
|
+
require "foreman/export/bluepill"
|
4
|
+
require "tmpdir"
|
5
|
+
|
6
|
+
describe Foreman::Export::Bluepill, :fakefs do
|
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) }
|
12
|
+
|
13
|
+
before(:each) { load_export_templates_into_fakefs("bluepill") }
|
14
|
+
before(:each) { allow(bluepill).to receive(:say) }
|
15
|
+
|
16
|
+
it "exports to the filesystem" do
|
17
|
+
bluepill.export
|
18
|
+
expect(normalize_space(File.read("/tmp/init/app.pill"))).to eq(normalize_space(example_export_file("bluepill/app.pill")))
|
19
|
+
end
|
20
|
+
|
21
|
+
it "cleans up if exporting into an existing dir" do
|
22
|
+
expect(FileUtils).to receive(:rm).with("/tmp/init/app.pill")
|
23
|
+
|
24
|
+
bluepill.export
|
25
|
+
bluepill.export
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with a process formation" do
|
29
|
+
let(:formation) { "alpha=2" }
|
30
|
+
|
31
|
+
it "exports to the filesystem with concurrency" do
|
32
|
+
bluepill.export
|
33
|
+
expect(normalize_space(File.read("/tmp/init/app.pill"))).to eq(normalize_space(example_export_file("bluepill/app-concurrency.pill")))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "foreman/engine"
|
3
|
+
require "foreman/export/daemon"
|
4
|
+
require "tmpdir"
|
5
|
+
|
6
|
+
describe Foreman::Export::Daemon, :fakefs do
|
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(:daemon) { Foreman::Export::Daemon.new("/tmp/init", engine, options) }
|
12
|
+
|
13
|
+
before(:each) { load_export_templates_into_fakefs("daemon") }
|
14
|
+
before(:each) { allow(daemon).to receive(:say) }
|
15
|
+
|
16
|
+
it "exports to the filesystem" do
|
17
|
+
daemon.export
|
18
|
+
|
19
|
+
expect(File.read("/tmp/init/app.conf")).to eq(example_export_file("daemon/app.conf"))
|
20
|
+
expect(File.read("/tmp/init/app-alpha.conf")).to eq(example_export_file("daemon/app-alpha.conf"))
|
21
|
+
expect(File.read("/tmp/init/app-alpha-1.conf")).to eq(example_export_file("daemon/app-alpha-1.conf"))
|
22
|
+
expect(File.read("/tmp/init/app-bravo.conf")).to eq(example_export_file("daemon/app-bravo.conf"))
|
23
|
+
expect(File.read("/tmp/init/app-bravo-1.conf")).to eq(example_export_file("daemon/app-bravo-1.conf"))
|
24
|
+
end
|
25
|
+
|
26
|
+
it "cleans up if exporting into an existing dir" do
|
27
|
+
expect(FileUtils).to receive(:rm).with("/tmp/init/app.conf")
|
28
|
+
expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha.conf")
|
29
|
+
expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha-1.conf")
|
30
|
+
expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo.conf")
|
31
|
+
expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo-1.conf")
|
32
|
+
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar.conf")
|
33
|
+
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar-1.conf")
|
34
|
+
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar.conf")
|
35
|
+
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar-1.conf")
|
36
|
+
|
37
|
+
daemon.export
|
38
|
+
daemon.export
|
39
|
+
end
|
40
|
+
|
41
|
+
it "does not delete exported files for similarly named applications" do
|
42
|
+
FileUtils.mkdir_p "/tmp/init"
|
43
|
+
|
44
|
+
["app2", "app2-alpha", "app2-alpha-1"].each do |name|
|
45
|
+
path = "/tmp/init/#{name}.conf"
|
46
|
+
FileUtils.touch(path)
|
47
|
+
expect(FileUtils).to_not receive(:rm).with(path)
|
48
|
+
end
|
49
|
+
|
50
|
+
daemon.export
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with a formation" do
|
54
|
+
let(:formation) { "alpha=2" }
|
55
|
+
|
56
|
+
it "exports to the filesystem with concurrency" do
|
57
|
+
daemon.export
|
58
|
+
|
59
|
+
expect(File.read("/tmp/init/app.conf")).to eq(example_export_file("daemon/app.conf"))
|
60
|
+
expect(File.read("/tmp/init/app-alpha.conf")).to eq(example_export_file("daemon/app-alpha.conf"))
|
61
|
+
expect(File.read("/tmp/init/app-alpha-1.conf")).to eq(example_export_file("daemon/app-alpha-1.conf"))
|
62
|
+
expect(File.read("/tmp/init/app-alpha-2.conf")).to eq(example_export_file("daemon/app-alpha-2.conf"))
|
63
|
+
expect(File.exist?("/tmp/init/app-bravo-1.conf")).to eq(false)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "with alternate templates" do
|
68
|
+
let(:template) { "/tmp/alternate" }
|
69
|
+
let(:options) { { :app => "app", :template => template } }
|
70
|
+
|
71
|
+
before do
|
72
|
+
FileUtils.mkdir_p template
|
73
|
+
File.open("#{template}/master.conf.erb", "w") { |f| f.puts "alternate_template" }
|
74
|
+
end
|
75
|
+
|
76
|
+
it "can export with alternate template files" do
|
77
|
+
daemon.export
|
78
|
+
expect(File.read("/tmp/init/app.conf")).to eq("alternate_template\n")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "with alternate templates from home dir" do
|
83
|
+
|
84
|
+
before do
|
85
|
+
FileUtils.mkdir_p File.expand_path("~/.foreman/templates/daemon")
|
86
|
+
File.open(File.expand_path("~/.foreman/templates/daemon/master.conf.erb"), "w") do |file|
|
87
|
+
file.puts "default_alternate_template"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it "can export with alternate template files" do
|
92
|
+
daemon.export
|
93
|
+
expect(File.read("/tmp/init/app.conf")).to eq("default_alternate_template\n")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "foreman/engine"
|
3
|
+
require "foreman/export/inittab"
|
4
|
+
require "tmpdir"
|
5
|
+
|
6
|
+
describe Foreman::Export::Inittab, :fakefs do
|
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
|
+
|
14
|
+
before(:each) { load_export_templates_into_fakefs("inittab") }
|
15
|
+
before(:each) { allow(inittab).to receive(:say) }
|
16
|
+
|
17
|
+
it "exports to the filesystem" do
|
18
|
+
inittab.export
|
19
|
+
expect(File.read("/tmp/inittab")).to eq(example_export_file("inittab/inittab.default"))
|
20
|
+
end
|
21
|
+
|
22
|
+
context "to stdout" do
|
23
|
+
let(:location) { "-" }
|
24
|
+
|
25
|
+
it "exports to stdout" do
|
26
|
+
expect(inittab).to receive(:puts).with(example_export_file("inittab/inittab.default"))
|
27
|
+
inittab.export
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with concurrency" do
|
32
|
+
let(:formation) { "alpha=2" }
|
33
|
+
|
34
|
+
it "exports to the filesystem with concurrency" do
|
35
|
+
inittab.export
|
36
|
+
expect(File.read("/tmp/inittab")).to eq(example_export_file("inittab/inittab.concurrency"))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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) { allow(launchd).to receive(:say) }
|
14
|
+
|
15
|
+
it "exports to the filesystem" do
|
16
|
+
launchd.export
|
17
|
+
expect(File.read("/tmp/init/app-alpha-1.plist")).to eq(example_export_file("launchd/launchd-a.default"))
|
18
|
+
expect(File.read("/tmp/init/app-bravo-1.plist")).to eq(example_export_file("launchd/launchd-b.default"))
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with multiple command arguments" do
|
22
|
+
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile", "charlie") }
|
23
|
+
|
24
|
+
it "splits each command argument" do
|
25
|
+
launchd.export
|
26
|
+
expect(File.read("/tmp/init/app-alpha-1.plist")).to eq(example_export_file("launchd/launchd-c.default"))
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "foreman/engine"
|
3
|
+
require "foreman/export/runit"
|
4
|
+
require "tmpdir"
|
5
|
+
|
6
|
+
describe Foreman::Export::Runit, :fakefs do
|
7
|
+
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile", 'bar=baz') }
|
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) }
|
11
|
+
|
12
|
+
before(:each) { load_export_templates_into_fakefs("runit") }
|
13
|
+
before(:each) { allow(runit).to receive(:say) }
|
14
|
+
before(:each) { allow(FakeFS::FileUtils).to receive(:chmod) }
|
15
|
+
|
16
|
+
it "exports to the filesystem" do
|
17
|
+
engine.env["BAR"] = "baz"
|
18
|
+
runit.export
|
19
|
+
|
20
|
+
expect(File.read("/tmp/init/app-alpha-1/run")).to eq(example_export_file('runit/app-alpha-1/run'))
|
21
|
+
expect(File.read("/tmp/init/app-alpha-1/log/run")).to eq(example_export_file('runit/app-alpha-1/log/run'))
|
22
|
+
expect(File.read("/tmp/init/app-alpha-1/env/PORT")).to eq("5000\n")
|
23
|
+
expect(File.read("/tmp/init/app-alpha-1/env/BAR")).to eq("baz\n")
|
24
|
+
expect(File.read("/tmp/init/app-alpha-2/run")).to eq(example_export_file('runit/app-alpha-2/run'))
|
25
|
+
expect(File.read("/tmp/init/app-alpha-2/log/run")).to eq(example_export_file('runit/app-alpha-2/log/run'))
|
26
|
+
expect(File.read("/tmp/init/app-alpha-2/env/PORT")).to eq("5001\n")
|
27
|
+
expect(File.read("/tmp/init/app-alpha-2/env/BAR")).to eq("baz\n")
|
28
|
+
expect(File.read("/tmp/init/app-bravo-1/run")).to eq(example_export_file('runit/app-bravo-1/run'))
|
29
|
+
expect(File.read("/tmp/init/app-bravo-1/log/run")).to eq(example_export_file('runit/app-bravo-1/log/run'))
|
30
|
+
expect(File.read("/tmp/init/app-bravo-1/env/PORT")).to eq("5100\n")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "creates a full path to the export directory" do
|
34
|
+
expect { runit.export }.to_not raise_error
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "foreman/engine"
|
3
|
+
require "foreman/export/supervisord"
|
4
|
+
require "tmpdir"
|
5
|
+
|
6
|
+
describe Foreman::Export::Supervisord, :fakefs do
|
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) }
|
12
|
+
|
13
|
+
before(:each) { load_export_templates_into_fakefs("supervisord") }
|
14
|
+
before(:each) { allow(supervisord).to receive(:say) }
|
15
|
+
|
16
|
+
it "exports to the filesystem" do
|
17
|
+
write_env(".env", "FOO"=>"bar", "URL"=>"http://example.com/api?foo=bar&baz=1")
|
18
|
+
supervisord.engine.load_env('.env')
|
19
|
+
supervisord.export
|
20
|
+
expect(File.read("/tmp/init/app.conf")).to eq(example_export_file("supervisord/app-alpha-1.conf"))
|
21
|
+
end
|
22
|
+
|
23
|
+
it "cleans up if exporting into an existing dir" do
|
24
|
+
expect(FileUtils).to receive(:rm).with("/tmp/init/app.conf")
|
25
|
+
supervisord.export
|
26
|
+
supervisord.export
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with concurrency" do
|
30
|
+
let(:formation) { "alpha=2" }
|
31
|
+
|
32
|
+
it "exports to the filesystem with concurrency" do
|
33
|
+
supervisord.export
|
34
|
+
expect(File.read("/tmp/init/app.conf")).to eq(example_export_file("supervisord/app-alpha-2.conf"))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|