Skip to content

Commit

Permalink
Fixes for new strategies (#7085)
Browse files Browse the repository at this point in the history
* Improve DockerDesktopClientProviderStrategy description
* Fix TestcontainersHostPropertyClientProviderStrategy only when tc.host is present

Fixes #7082
  • Loading branch information
eddumelendez committed May 31, 2023
1 parent 5c88064 commit e368f71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private Path resolveSocketPath() {

@Override
public String getDescription() {
return "Rootless Docker accessed via Unix socket (" + getSocketPath() + ")";
return "Docker accessed via Unix socket (" + getSocketPath() + ")";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class TestcontainersHostPropertyClientProviderStrategy extends Dock

public static final int PRIORITY = EnvironmentAndSystemPropertyClientProviderStrategy.PRIORITY - 10;

private final DockerClientConfig dockerClientConfig;
private DockerClientConfig dockerClientConfig;

public TestcontainersHostPropertyClientProviderStrategy() {
this(DefaultDockerClientConfig.createDefaultConfigBuilder());
Expand All @@ -28,8 +28,10 @@ public TestcontainersHostPropertyClientProviderStrategy() {
TestcontainersConfiguration.getInstance().getUserProperty("tc.host", null)
);

tcHost.ifPresent(configBuilder::withDockerHost);
this.dockerClientConfig = configBuilder.build();
if (tcHost.isPresent()) {
configBuilder.withDockerHost(tcHost.get());
this.dockerClientConfig = configBuilder.build();
}
}

@Override
Expand All @@ -46,6 +48,11 @@ public TransportConfig getTransportConfig() throws InvalidConfigurationException
.build();
}

@Override
protected boolean isApplicable() {
return this.dockerClientConfig != null;
}

@Override
protected int getPriority() {
return PRIORITY;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.testcontainers.dockerclient;

import com.github.dockerjava.core.DefaultDockerClientConfig;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -24,16 +22,6 @@ public class TestcontainersHostPropertyClientProviderStrategyTest {

private URI defaultDockerHost;

private com.github.dockerjava.core.SSLConfig defaultSSLConfig;

@Before
public void checkEnvironmentClear() {
// If docker-java picks up non-default settings from the environment, our test needs to know to expect those
DefaultDockerClientConfig defaultConfig = DefaultDockerClientConfig.createDefaultConfigBuilder().build();
this.defaultDockerHost = defaultConfig.getDockerHost();
this.defaultSSLConfig = defaultConfig.getSSLConfig();
}

@Test
public void tcHostPropertyIsProvided() {
Mockito
Expand All @@ -43,9 +31,9 @@ public void tcHostPropertyIsProvided() {

TestcontainersHostPropertyClientProviderStrategy strategy = new TestcontainersHostPropertyClientProviderStrategy();

assertThat(strategy.isApplicable()).isTrue();
TransportConfig transportConfig = strategy.getTransportConfig();
assertThat(transportConfig.getDockerHost().toString()).isEqualTo("tcp://127.0.0.1:9000");
assertThat(transportConfig.getSslConfig()).isEqualTo(this.defaultSSLConfig);
}

@Test
Expand All @@ -54,8 +42,6 @@ public void tcHostPropertyIsNotProvided() {

TestcontainersHostPropertyClientProviderStrategy strategy = new TestcontainersHostPropertyClientProviderStrategy();

TransportConfig transportConfig = strategy.getTransportConfig();
assertThat(transportConfig.getDockerHost()).isEqualTo(this.defaultDockerHost);
assertThat(transportConfig.getSslConfig()).isEqualTo(this.defaultSSLConfig);
assertThat(strategy.isApplicable()).isFalse();
}
}

0 comments on commit e368f71

Please sign in to comment.