[Bug]: DockerDesktopClientProviderStrategy is always applicable

Đang mở Phù hợp với người mới
#11,829 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
docker, java
Lĩnh vực
testing-qa

Hướng nghiên cứu

Kiểm tra DockerDesktopClientProviderStrategy, tập trung vào socketPath, isApplicable() và getTransportConfig(). Trước tiên, hãy tái hiện việc lựa chọn strategy trên macOS không có Docker Desktop, sau đó xem lại các test lân cận hoặc test suite của strategy. Hoàn tất khi strategy không được chọn nếu socket của nó không khả dụng và không xảy ra NullPointerException trong khi thử các cấu hình.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

type/bug
Module

Core

Testcontainers version

2.0.5

Using the latest Testcontainers version?

Yes

Host OS

macOS

Host Arch

ARM

Docker version
29.5.3
What happened?

DockerDesktopClientProviderStrategy is always applicable even when Docker Desktop is not installed at all. It happens because the socketPath field is annotated with @Getter(lazy = true) and so its actual type is AtomicReference, but the isApplicable() method checks nullability as this.socketPath != null.

@Getter(lazy = true)
@Nullable
private final Path socketPath = resolveSocketPath();

@Override
protected boolean isApplicable() {
    return (SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC) && this.socketPath != null;
}

Finally, the getTransportConfig() method fails with NPE as getSocketPath() returns null.

@Override
public TransportConfig getTransportConfig() throws InvalidConfigurationException {
    return TransportConfig.builder().dockerHost(URI.create("unix://" + getSocketPath().toString())).build();
}
Relevant log output
[Test worker] ERROR o.t.d.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
	UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock)
	DockerDesktopClientProviderStrategy: failed with exception NullPointerException (Cannot invoke "java.nio.file.Path.toString()" because the return value of "org.testcontainers.dockerclient.DockerDesktopClientProviderStrategy.getSocketPath()" is null)
Additional Information

No response

Ngôn ngữ chính
Java
Star
8.7k
Fork
1.9k
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
9

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của testcontainers/testcontainers-java

Tất cả issue của testcontainers/testcontainers-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.