-
Notifications
You must be signed in to change notification settings - Fork 552
Move default Docker constants + methods into DockerHost #441
Conversation
addresses #440 |
@@ -1685,9 +1684,11 @@ public static Builder builder() { | |||
* @throws DockerCertificateException if we could not build a DockerCertificates object | |||
*/ | |||
public static Builder fromEnv() throws DockerCertificateException { | |||
final String endpoint = fromNullable(getenv("DOCKER_HOST")).or(defaultEndpoint()); | |||
final DockerUtils dockerUtils = new DockerUtils(); | |||
final String endpoint = fromNullable(getenv("DOCKER_HOST")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exact series of method calls—fromNullable(getenv("DOCKER_HOST")).or(dockerUtils.defaultDockerEndpoint());
—is used multiple times in different places. It seems to me this would be better as a single method in DockerUtils
, something like getHost()
.
Same with fromNullable(getenv("DOCKER_CERT_PATH")).or(dockerUtils.defaultCertPath())
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good point
On Thursday, May 19, 2016, Flavin notifications@github.com wrote:
In src/main/java/com/spotify/docker/client/DefaultDockerClient.java
#441 (comment):@@ -1685,9 +1684,11 @@ public static Builder builder() {
* @throws DockerCertificateException if we could not build a DockerCertificates object
*/
public static Builder fromEnv() throws DockerCertificateException {
- final String endpoint = fromNullable(getenv("DOCKER_HOST")).or(defaultEndpoint());
- final DockerUtils dockerUtils = new DockerUtils();
- final String endpoint = fromNullable(getenv("DOCKER_HOST"))
This exact series of method calls—
fromNullable(getenv("DOCKER_HOST")).or(dockerUtils.defaultDockerEndpoint());—is
used multiple times in different places. It seems to me this would be
better as a single method in DockerUtils, something like getHost().Same with
fromNullable(getenv("DOCKER_CERT_PATH")).or(dockerUtils.defaultCertPath())
.—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
https://github.com/spotify/docker-client/pull/441/files/ac2c911da1dc2013c62a4f2950d13ae9857742da#r63953389
David Xia
Software Engineer
dxia@spotify.com
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or easier to read IMHO:
endpoint = MoreObjects.firstNonNull(System.getenv("DOCKER_HOST"), dockerUtils.defaultCertPath());
|
Default Docker constants and methods for constructing them were duplicated in `DockerHost` and `DefaultDockerClient`. Move them all into `DockerHost` and add tests.
ac2c911
to
dcafa07
Compare
String getenv(String name); | ||
} | ||
|
||
private static SystemDelegate systemDelegate = new SystemDelegate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this as a static attribute that you can set during tests seems bad, but if this is an instance attribute, all the currently static methods like endpointFromEnv()
would have to go into another static class in order to be used by the static factory method fromEnv()
. Since setSystemDelegate()
is package local, I thought this is OK although inelegant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could get away from this whole thing by having a way to pass in the "env" or "system properties" as a Map<String, String>
in the test, rather than having to swap out a "delegate".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattnworb Just for my own edification, in cases like this where you want to test a static method (eg defaultDockerEndpoint()
) that calls an external depedency's final class' static methods (eg System.getProperty()
), what are good approaches, if any? I set the static attribute with a package local static method, but what are other ways?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is here feels like the best thing that I know of for this case. I suppose it is worth minimizing the chain of static method -> static method calls because of this reason.
👍 |
Add public methods to get DockerHost constants. Add more tests.
Default Docker constants and methods for constructing them were
duplicated in
DockerHost
andDefaultDockerClient
. Move them all intoDockerHost
and add tests.