forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestutil_test.go
39 lines (30 loc) · 1015 Bytes
/
testutil_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
package testutil
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestDockerHost(t *testing.T) {
t.Run("no DOCKER_HOST set", func(t *testing.T) {
err := os.Unsetenv("DOCKER_HOST")
require.NoError(t, err)
host := GetLocalHost()
if host != localhost {
t.Fatalf("Host should be localhost when DOCKER_HOST is not set. Current value [%s]", host)
}
})
t.Run("DOCKER_HOST with IP address only", func(t *testing.T) {
t.Setenv("DOCKER_HOST", "1.1.1.1")
host := GetLocalHost()
if host != "1.1.1.1" {
t.Fatalf("Host should take DOCKER_HOST value when set. Current value is [%s] and DOCKER_HOST is [%s]", host, os.Getenv("DOCKER_HOST"))
}
})
t.Run("DOCKER_HOST with protocol, IP address, and port", func(t *testing.T) {
t.Setenv("DOCKER_HOST", "tcp://1.1.1.1:8080")
host := GetLocalHost()
if host != "1.1.1.1" {
t.Fatalf("Host should take DOCKER_HOST value when set. Current value is [%s] and DOCKER_HOST is [%s]", host, os.Getenv("DOCKER_HOST"))
}
})
}