forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider_test.go
75 lines (68 loc) · 1.99 KB
/
provider_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package testcontainers
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go/internal/core"
)
func TestProviderTypeGetProviderAutodetect(t *testing.T) {
dockerHost := core.MustExtractDockerHost(context.Background())
const podmanSocket = "unix://$XDG_RUNTIME_DIR/podman/podman.sock"
tests := []struct {
name string
tr ProviderType
DockerHost string
want string
}{
{
name: "default provider without podman.socket",
tr: ProviderDefault,
DockerHost: dockerHost,
want: Bridge,
},
{
name: "default provider with podman.socket",
tr: ProviderDefault,
DockerHost: podmanSocket,
want: Podman,
},
{
name: "docker provider without podman.socket",
tr: ProviderDocker,
DockerHost: dockerHost,
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: dockerHost,
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) {
if tt.tr == ProviderPodman && core.IsWindows() {
t.Skip("Podman provider is not implemented for Windows")
}
t.Setenv("DOCKER_HOST", tt.DockerHost)
got, err := tt.tr.GetProvider()
require.NoErrorf(t, err, "ProviderType.GetProvider()")
provider, ok := got.(*DockerProvider)
require.Truef(t, ok, "ProviderType.GetProvider() = %T, want %T", got, &DockerProvider{})
require.Equalf(t, tt.want, provider.defaultBridgeNetworkName, "ProviderType.GetProvider() = %v, want %v", provider.defaultBridgeNetworkName, tt.want)
})
}
}