spec/invoker/config_spec.rb in invoker-1.3.2 vs spec/invoker/config_spec.rb in invoker-1.4.0

- old
+ new

@@ -77,17 +77,17 @@ file.close config = Invoker::Parsers::Config.new(file.path, 9000) command1 = config.processes.first - expect(command1.port).to eq(9001) - expect(command1.cmd).to match(/9001/) + expect(command1.port).to eq(9000) + expect(command1.cmd).to match(/9000/) command2 = config.processes[1] - expect(command2.port).to eq(9002) - expect(command2.cmd).to match(/9002/) + expect(command2.port).to eq(9001) + expect(command2.cmd).to match(/9001/) command2 = config.processes[2] expect(command2.port).to be_nil ensure @@ -116,12 +116,12 @@ file.close config = Invoker::Parsers::Config.new(file.path, 9000) command1 = config.processes.first - expect(command1.port).to eq(9001) - expect(command1.cmd).to match(/9001/) + expect(command1.port).to eq(9000) + expect(command1.cmd).to match(/9000/) command2 = config.processes[1] expect(command2.port).to eq(3000) @@ -160,11 +160,11 @@ EOD } config = Invoker::Parsers::Config.new("/tmp/Procfile", 9000) command1 = config.processes.first - expect(command1.port).to eq(9001) + expect(command1.port).to eq(9000) expect(command1.cmd).to match(/bundle exec rails/) ensure File.delete("/tmp/Procfile") end end @@ -181,11 +181,11 @@ Invoker.load_invoker_config("/tmp/Procfile", 9000) dns_cache = Invoker::DNSCache.new(Invoker.config) expect(dns_cache.dns_data).to_not be_empty expect(dns_cache.dns_data['web']).to_not be_empty - expect(dns_cache.dns_data['web']['port']).to eql 9001 + expect(dns_cache.dns_data['web']['port']).to eql 9000 ensure File.delete("/tmp/Procfile") end end end @@ -218,9 +218,104 @@ config = Invoker::Parsers::Config.new(file.path, 9000) expect(config.autorunnable_processes.map(&:label)).to eq(['postgres', 'memcached', 'panda-auth']) ensure file.unlink() + end + end + end + + describe "global config file" do + it "should use global config file if available" do + begin + filename = "#{Invoker::Power::Config.config_dir}/foo.ini" + file = File.open(filename, "w") + config_data =<<-EOD +[try_sleep] +directory = /tmp +command = ruby try_sleep.rb + EOD + file.write(config_data) + file.close + config = Invoker::Parsers::Config.new("foo", 9000) + expect(config.filename).to eql(filename) + ensure + File.unlink(filename) + end + end + end + + describe "config file autodetection" do + context "no config file given" do + + def create_invoker_ini + file = File.open("invoker.ini", "w") + config_data =<<-EOD +[some_process] +command = some_command + EOD + file.write(config_data) + file.close + + file + end + + def create_procfile + file = File.open("Procfile", "w") + config_data =<<-EOD +some_other_process: some_other_command + EOD + file.write(config_data) + file.close + + file + end + + context "directory has invoker.ini" do + it "autodetects invoker.ini" do + begin + file = create_invoker_ini + + config = Invoker::Parsers::Config.new(nil, 9000) + expect(config.process("some_process").cmd).to eq("some_command") + ensure + File.delete(file) + end + end + end + + context "directory has Procfile" do + it "autodetects Procfile" do + begin + file = create_procfile + + config = Invoker::Parsers::Config.new(nil, 9000) + expect(config.process("some_other_process").cmd).to eq("some_other_command") + ensure + File.delete(file) + end + end + end + + context "directory has both invoker.ini and Procfile" do + it "prioritizes invoker.ini" do + begin + invoker_ini = create_invoker_ini + procfile = create_procfile + + config = Invoker::Parsers::Config.new(nil, 9000) + expect(config.process("some_process").cmd).to eq("some_command") + ensure + File.delete(invoker_ini) + File.delete(procfile) + end + end + end + + context "directory doesn't have invoker.ini or Procfile" do + it "aborts" do + expect { Invoker::Parsers::Config.new(nil, 9000) }.to raise_error(SystemExit) + end end end end end