forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider_test.go
81 lines (75 loc) · 2.1 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
76
77
78
79
80
81
package testcontainers
import (
"context"
"testing"
"github.com/testcontainers/testcontainers-go/internal/testcontainersdocker"
)
func TestProviderTypeGetProviderAutodetect(t *testing.T) {
dockerHost := testcontainersdocker.ExtractDockerHost(context.Background())
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: 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 && testcontainersdocker.IsWindows() {
t.Skip("Podman provider is not implemented for Windows")
}
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)
}
})
}
}