Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoint_url #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thiamsantos
Copy link
Contributor

Motivation

Sometime can be a little annoying to add the endpoint_url to every test file or add it to the test case.
As the endpoint url is something that in the majority of times the test needs to interact to be able to use bypass, seems to make sense that it could be grabbed easily. The port seems to be something more internal that not all tests would need to know and use.

Proposed Solution

Add endpoint_url field to bypass struct. Existing code would work normally with existing port attribute.

Copy link
Contributor

@bszaf bszaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow up with described changes.

@@ -44,7 +44,7 @@ defmodule Bypass do
pid = start_instance(opts)
port = Bypass.Instance.call(pid, :port)
debug_log("Did open connection #{inspect(pid)} on port #{inspect(port)}")
bypass = %Bypass{pid: pid, port: port}
bypass = %Bypass{pid: pid, port: port, endpoint_url: "http://localhost:#{port}/"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localhost is usually resolves to loopback interface address - 127.0.0.1, however it is possible to bind to different interface. Therefore, the URL might not work.

It's safer to use use :inet.sockname/1 https://www.erlang.org/doc/man/inet.html#sockname-1 to retrieve listening address and then derive an interface address from :inet.getifaddrs/0 https://www.erlang.org/doc/man/inet.html#getifaddrs-0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some overlap with a PR I just created. For the ip address I made this PR: #137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants