Skip to content

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.

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