Skip to content

Commit 969325c

Browse files
committed
Add unit test for proxy
Make sure that the proxy is configured properly when added to client.
1 parent f2dcb6c commit 969325c

1 file changed

Lines changed: 6 additions & 20 deletions

File tree

spec/lib/twingly/http_spec.rb

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -689,11 +689,9 @@ class CustomError < StandardError; end
689689
end
690690
end
691691

692-
fdescribe "proxy" do
693-
let(:test_url) { "http://example.com" }
694-
695-
context "when a proxy is set" do
696-
let(:proxy_url) { "http://localhost:1080" }
692+
describe "proxy" do
693+
context "when a proxy is provided" do
694+
let(:proxy_url) { "http://127.0.0.1:8080" }
697695
let(:proxy_client) do
698696
described_class.new(
699697
base_user_agent: base_user_agent,
@@ -703,22 +701,10 @@ class CustomError < StandardError; end
703701
)
704702
end
705703

706-
before(:all) do
707-
let(:toxiproxy) { Toxiproxy.new(host: "localhost", port: 8474) }
708-
let(:proxy) { toxiproxy.create("proxy", listen: "localhost:1080", upstream: "https://example.com") }
709-
end
710-
711-
after(:all) do
712-
proxy.delete
713-
toxiproxy.close
714-
end
715-
716-
it "sets the proxy URL correctly in the Twingly HTTP client" do
717-
allow(proxy_client).to receive(proxy).and_return(proxy_url)
718-
response = proxy_client.get("https://example.com")
704+
it "sets the proxy" do
705+
connection = proxy_client.send(:create_http_client)
719706

720-
expect(proxy_client.proxy).to eq(proxy_url)
721-
expect(response.status).to eq(200)
707+
expect(connection.proxy.uri.to_s).to eq(proxy_url)
722708
end
723709
end
724710
end

0 commit comments

Comments
 (0)