forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Auto detect the use of Podman from DOCKER_HOST (testcontainers#982
) * feat: Autodetect the use of Podman if no provider is set, and DOCKER_HOST contains podman.sock Updated documentation Unit tests for auto-detection of ProviderPodman Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com> * Cleanup linter issues * Use `t.Setenv()` in tests * Fix the spelling of reap --------- Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com> Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>
- Loading branch information
1 parent
88a7f81
commit c0f7111
Showing
3 changed files
with
134 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package testcontainers | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestProviderTypeGetProviderAutodetect(t *testing.T) { | ||
const dockerSocket = "unix:///var/run/docker.sock" | ||
const podmanSocket = "unix://$XDG_RUNTIME_DIR/podman/podman.sock" | ||
|
||
tests := []struct { | ||
name string | ||
tr ProviderType | ||
DockerHost string | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "default provider without podman.socket", | ||
tr: ProviderDefault, | ||
DockerHost: dockerSocket, | ||
want: Bridge, | ||
}, | ||
{ | ||
name: "default provider with podman.socket", | ||
tr: ProviderDefault, | ||
DockerHost: podmanSocket, | ||
want: Podman, | ||
}, | ||
{ | ||
name: "docker provider without podman.socket", | ||
tr: ProviderDocker, | ||
DockerHost: dockerSocket, | ||
want: Bridge, | ||
}, | ||
{ | ||
// Explicitly setting Docker provider should not be overridden by auto-detect | ||
name: "docker provider with podman.socket", | ||
tr: ProviderDocker, | ||
DockerHost: podmanSocket, | ||
want: Bridge, | ||
}, | ||
{ | ||
name: "Podman provider without podman.socket", | ||
tr: ProviderPodman, | ||
DockerHost: dockerSocket, | ||
want: Podman, | ||
}, | ||
{ | ||
name: "Podman provider with podman.socket", | ||
tr: ProviderPodman, | ||
DockerHost: podmanSocket, | ||
want: Podman, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Setenv("DOCKER_HOST", tt.DockerHost) | ||
|
||
got, err := tt.tr.GetProvider() | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ProviderType.GetProvider() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
provider, ok := got.(*DockerProvider) | ||
if !ok { | ||
t.Fatalf("ProviderType.GetProvider() = %T, want %T", got, &DockerProvider{}) | ||
} | ||
if provider.defaultBridgeNetworkName != tt.want { | ||
t.Errorf("ProviderType.GetProvider() = %v, want %v", provider.defaultBridgeNetworkName, tt.want) | ||
} | ||
}) | ||
} | ||
} |