forked from nginx-proxy/docker-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
78 lines (65 loc) · 1.54 KB
/
utils_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
package main
import (
"flag"
"os"
"testing"
)
func TestDefaultEndpoint(t *testing.T) {
endpoint, err := getEndpoint()
if err != nil {
t.Fatal("%s", err)
}
if endpoint != "unix:///var/run/docker.sock" {
t.Fatal("Expected unix:///var/run/docker.sock")
}
}
func TestDockerHostEndpoint(t *testing.T) {
err := os.Setenv("DOCKER_HOST", "tcp://127.0.0.1:4243")
if err != nil {
t.Fatalf("Unable to set DOCKER_HOST: %s", err)
}
endpoint, err := getEndpoint()
if err != nil {
t.Fatal("%s", err)
}
if endpoint != "tcp://127.0.0.1:4243" {
t.Fatal("Expected tcp://127.0.0.1:4243")
}
}
func TestDockerFlagEndpoint(t *testing.T) {
initFlags()
err := os.Setenv("DOCKER_HOST", "tcp://127.0.0.1:4243")
if err != nil {
t.Fatalf("Unable to set DOCKER_HOST: %s", err)
}
// flag value should override DOCKER_HOST and default value
err = flag.Set("endpoint", "tcp://127.0.0.1:5555")
if err != nil {
t.Fatalf("Unable to set endpoint flag: %s", err)
}
endpoint, err := getEndpoint()
if err != nil {
t.Fatal("%s", err)
}
if endpoint != "tcp://127.0.0.1:5555" {
t.Fatal("Expected tcp://127.0.0.1:5555")
}
}
func TestUnixNotExists(t *testing.T) {
endpoint = ""
err := os.Setenv("DOCKER_HOST", "unix:///does/not/exist")
if err != nil {
t.Fatalf("Unable to set DOCKER_HOST: %s", err)
}
_, err = getEndpoint()
if err == nil {
t.Fatal("endpoint should have failed")
}
}
func TestUnixBadFormat(t *testing.T) {
endpoint = "unix:/var/run/docker.sock"
_, err := getEndpoint()
if err == nil {
t.Fatal("endpoint should have failed")
}
}