forked from ddollar/foreman
/
engine_spec.rb
98 lines (84 loc) · 2.74 KB
/
engine_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require "spec_helper"
require "foreman/engine"
describe "Foreman::Engine" do
subject { Foreman::Engine.new("Procfile", {}) }
describe "initialize" do
describe "without an existing Procfile" do
it "raises an error" do
lambda { subject }.should raise_error
end
end
describe "with a Procfile" do
before { write_procfile }
it "reads the processes" do
subject.processes["alpha"].command.should == "./alpha"
subject.processes["bravo"].command.should == "./bravo"
end
end
describe "with a deprecated Procfile" do
before do
File.open("Procfile", "w") do |file|
file.puts "name command"
end
end
it "should print a deprecation warning" do
mock(subject).warn_deprecated_procfile!
subject.processes.length.should == 1
end
end
end
describe "start" do
it "forks the processes" do
write_procfile
mock(subject).fork(subject.processes["alpha"], {}, {})
mock(subject).fork(subject.processes["bravo"], {}, {})
mock(subject).watch_for_termination
subject.start
end
it "handles concurrency" do
write_procfile
engine = Foreman::Engine.new("Procfile",:concurrency => "alpha=2")
mock(engine).fork_individual(engine.processes["alpha"], 1, 5000, {})
mock(engine).fork_individual(engine.processes["alpha"], 2, 5001, {})
mock(engine).fork_individual(engine.processes["bravo"], 1, 5100, {})
mock(engine).watch_for_termination
engine.start
end
end
describe "execute" do
it "runs the processes" do
write_procfile
mock(subject).fork(subject.processes["alpha"], {}, {})
mock(subject).watch_for_termination
subject.execute("alpha")
end
end
describe "environment" do
before(:each) do
write_procfile
stub(Process).fork
end
it "should read if specified" do
File.open("/tmp/env", "w") { |f| f.puts("FOO=baz") }
engine = Foreman::Engine.new("Procfile", :env => "/tmp/env")
stub(engine).info
mock(engine).watch_for_termination
engine.execute("alpha")
end
it "should fail if specified and doesnt exist" do
mock.instance_of(Foreman::Engine).error("No such file: /tmp/env")
engine = Foreman::Engine.new("Procfile", :env => "/tmp/env")
stub(engine).info
mock(engine).watch_for_termination
engine.execute("alpha")
end
it "should read .env if none specified" do
File.open(".env", "w") { |f| f.puts("FOO=qoo") }
engine = Foreman::Engine.new("Procfile")
stub(engine).info
mock(engine).watch_for_termination
mock(engine).fork_individual(anything, anything, anything, { "FOO" => "qoo" })
engine.execute("bravo")
end
end
end