spec/invoker/power/balancer_spec.rb in invoker-1.3.2 vs spec/invoker/power/balancer_spec.rb in invoker-1.4.0
- old
+ new
@@ -1,75 +1,22 @@
require 'spec_helper'
describe Invoker::Power::Balancer do
before do
- @balancer = Invoker::Power::Balancer.new(mock("connection"), "http")
+ @http_connection = mock("connection")
+ @balancer = Invoker::Power::Balancer.new(@http_connection, "http")
end
- context "matching domain part of incoming request" do
- it "should do foo.dev match" do
- match = @balancer.extract_host_from_domain("foo.dev")
- expect(match).to_not be_nil
-
- matching_string = match[1]
- expect(matching_string).to eq("foo")
+ context "when Host field is missing in the request" do
+ it "should return 400 as response when Host is missing" do
+ headers = {}
+ @http_connection.expects(:send_data).with() { |value| value =~ /400 Bad Request/i }
+ @balancer.headers_received(headers)
end
- it "should match foo.dev:1080" do
- match = @balancer.extract_host_from_domain("foo.dev:1080")
- expect(match).to_not be_nil
-
- matching_string = match[1]
- expect(matching_string).to eq("foo")
- end
-
- it "should match emacs.bar.dev" do
- match = @balancer.extract_host_from_domain("emacs.bar.dev")
- expect(match).to_not be_nil
-
- matching_string = match[1]
- expect(matching_string).to eq("bar")
- end
-
- it "should match hello-world.dev" do
- match = @balancer.extract_host_from_domain("hello-world.dev")
- expect(match).to_not be_nil
-
- matching_string = match[1]
- expect(matching_string).to eq("hello-world")
- end
- end
-
- context "matching domain part of incoming request using xip.io" do
- it "should do foo.10.0.0.1.xip.io match" do
- match = @balancer.extract_host_from_domain("foo.10.0.0.1.xip.io")
- expect(match).to_not be_nil
-
- matching_string = match[1]
- expect(matching_string).to eq("foo")
- end
-
- it "should match foo.10.0.0.1.xip.io:1080" do
- match = @balancer.extract_host_from_domain("foo.10.0.0.1.xip.io:1080")
- expect(match).to_not be_nil
-
- matching_string = match[1]
- expect(matching_string).to eq("foo")
- end
-
- it "should match emacs.bar.10.0.0.1.xip.io" do
- match = @balancer.extract_host_from_domain("emacs.bar.10.0.0.1.xip.io")
- expect(match).to_not be_nil
-
- matching_string = match[1]
- expect(matching_string).to eq("bar")
- end
-
- it "should match hello-world.10.0.0.1.xip.io" do
- match = @balancer.extract_host_from_domain("hello-world.10.0.0.1.xip.io")
- expect(match).to_not be_nil
-
- matching_string = match[1]
- expect(matching_string).to eq("hello-world")
+ it "should return 400 as response when Host is empty" do
+ headers = { 'Host' => '' }
+ @http_connection.expects(:send_data).with() { |value| value =~ /400 Bad Request/i }
+ @balancer.headers_received(headers)
end
end
end