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

Fixes for new strategies #7085

Merged
merged 3 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading