testcontainers / testcontainers/testcontainers-java

[Bug]: DockerDesktopClientProviderStrategy is always applicable

Aperta Adatta ai principianti
#11,829 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

type/bug
Lingua principale
Java
Stelle
8.7k
Fork
1.9k
Merge medio
2g 17h
PR unite (30g)
9

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Ispeziona DockerDesktopClientProviderStrategy, concentrandoti su socketPath, isApplicable() e getTransportConfig(). Inizia riproducendo la selezione della strategia su macOS senza Docker Desktop, quindi esamina i test nelle vicinanze o la suite di test della strategia. Il lavoro è completato quando la strategia non viene selezionata se il suo socket non è disponibile e non si verifica alcuna NullPointerException mentre si tenta di usare le configurazioni.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
docker, java
Ambito
testing-qa
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
74/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.