-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaemon_unix_test.go
114 lines (92 loc) · 3.65 KB
/
daemon_unix_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// +build !windows,!solaris
// TODO: Create new file for Solaris which tests config parameters
// as described in daemon/config_solaris.go
package main
import (
"github.com/docker/docker/daemon"
"github.com/docker/docker/pkg/testutil/assert"
"github.com/docker/docker/pkg/testutil/tempfile"
"testing"
)
func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
content := `{"log-opts": {"max-size": "1k"}}`
tempFile := tempfile.NewTempFile(t, "config", content)
defer tempFile.Remove()
opts := defaultOptions(tempFile.Name())
opts.common.Debug = true
opts.common.LogLevel = "info"
assert.NilError(t, opts.flags.Set("selinux-enabled", "true"))
loadedConfig, err := loadDaemonCliConfig(opts)
assert.NilError(t, err)
assert.NotNil(t, loadedConfig)
assert.Equal(t, loadedConfig.Debug, true)
assert.Equal(t, loadedConfig.LogLevel, "info")
assert.Equal(t, loadedConfig.EnableSelinuxSupport, true)
assert.Equal(t, loadedConfig.LogConfig.Type, "json-file")
assert.Equal(t, loadedConfig.LogConfig.Config["max-size"], "1k")
}
func TestLoadDaemonConfigWithNetwork(t *testing.T) {
content := `{"bip": "127.0.0.2", "ip": "127.0.0.1"}`
tempFile := tempfile.NewTempFile(t, "config", content)
defer tempFile.Remove()
opts := defaultOptions(tempFile.Name())
loadedConfig, err := loadDaemonCliConfig(opts)
assert.NilError(t, err)
assert.NotNil(t, loadedConfig)
assert.Equal(t, loadedConfig.IP, "127.0.0.2")
assert.Equal(t, loadedConfig.DefaultIP.String(), "127.0.0.1")
}
func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
content := `{
"cluster-store-opts": {"kv.cacertfile": "/var/lib/docker/discovery_certs/ca.pem"},
"log-opts": {"tag": "test"}
}`
tempFile := tempfile.NewTempFile(t, "config", content)
defer tempFile.Remove()
opts := defaultOptions(tempFile.Name())
loadedConfig, err := loadDaemonCliConfig(opts)
assert.NilError(t, err)
assert.NotNil(t, loadedConfig)
assert.NotNil(t, loadedConfig.ClusterOpts)
expectedPath := "/var/lib/docker/discovery_certs/ca.pem"
assert.Equal(t, loadedConfig.ClusterOpts["kv.cacertfile"], expectedPath)
assert.NotNil(t, loadedConfig.LogConfig.Config)
assert.Equal(t, loadedConfig.LogConfig.Config["tag"], "test")
}
func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
content := `{ "userland-proxy": false }`
tempFile := tempfile.NewTempFile(t, "config", content)
defer tempFile.Remove()
opts := defaultOptions(tempFile.Name())
loadedConfig, err := loadDaemonCliConfig(opts)
assert.NilError(t, err)
assert.NotNil(t, loadedConfig)
assert.NotNil(t, loadedConfig.ClusterOpts)
assert.Equal(t, loadedConfig.EnableUserlandProxy, false)
// make sure reloading doesn't generate configuration
// conflicts after normalizing boolean values.
reload := func(reloadedConfig *daemon.Config) {
assert.Equal(t, reloadedConfig.EnableUserlandProxy, false)
}
assert.NilError(t, daemon.ReloadConfiguration(opts.configFile, opts.flags, reload))
}
func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
tempFile := tempfile.NewTempFile(t, "config", `{}`)
defer tempFile.Remove()
opts := defaultOptions(tempFile.Name())
loadedConfig, err := loadDaemonCliConfig(opts)
assert.NilError(t, err)
assert.NotNil(t, loadedConfig)
assert.NotNil(t, loadedConfig.ClusterOpts)
assert.Equal(t, loadedConfig.EnableUserlandProxy, true)
}
func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
content := `{"disable-legacy-registry": true}`
tempFile := tempfile.NewTempFile(t, "config", content)
defer tempFile.Remove()
opts := defaultOptions(tempFile.Name())
loadedConfig, err := loadDaemonCliConfig(opts)
assert.NilError(t, err)
assert.NotNil(t, loadedConfig)
assert.Equal(t, loadedConfig.V2Only, true)
}