Skip to content

Commit

Permalink
Add tests for #select_backend_config
Browse files Browse the repository at this point in the history
  • Loading branch information
bhenderson committed Oct 9, 2017
1 parent cf0fc64 commit 8a03b5c
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions spec/invoker/power/url_rewriter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@
expect(match[0]).to eq("hello-world")
end

it "should match lots of dots" do
match = rewriter.extract_host_from_domain("a.b.c.d.dev")
expect(match).to_not be_empty

expect(match[0]).to eq("a.b.c.d")
expect(match[1]).to eq("d")
end

it "should not match foo.local" do
match = rewriter.extract_host_from_domain("foo.local")
expect(match).to be_empty
end

context 'user sets up a custom top level domain' do
before(:all) do
@original_invoker_config = Invoker.config
Expand All @@ -66,5 +79,51 @@
Invoker.config = @original_invoker_config
end
end

context '#select_backend_config' do
before(:all) do
@original_invoker_config = Invoker.dns_cache
@processes = [
{ label: 'foo', port: 1 },
{ label: 'api.foo', port: 2 },
{ label: 'bar.foo', port: 3 },
].map{ |p| OpenStruct.new(p) }
Invoker.config.stubs(:processes).returns(@processes)
Invoker.dns_cache = Invoker::DNSCache.new(nil)
end

before do
def rewriter.dns_check(*args)
socket = StringIO.new
Invoker::IPC::DnsCheckCommand.new(socket).run_command(Invoker::IPC::Message::DnsCheck.new(*args))
socket.rewind
Invoker::IPC.message_from_io socket
end
end

after(:all) do
Invoker.dns_cache = @original_invoker_config
end

it 'matches foo.dev' do
match = rewriter.select_backend_config('foo.dev')
expect(match.port).to eql(1)
end

it 'matches api.foo.dev' do
match = rewriter.select_backend_config('api.foo.dev')
expect(match.port).to eql(2)
end

it 'matches bar.foo.dev' do
match = rewriter.select_backend_config('bar.foo.dev')
expect(match.port).to eql(3)
end

it 'matches baz.foo.dev' do
match = rewriter.select_backend_config('baz.foo.dev')
expect(match.port).to eql(1)
end
end
end
end

0 comments on commit 8a03b5c

Please sign in to comment.