github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/cmd/dockerd/daemon_unix_test.go (about) 1 // +build !windows 2 3 package main 4 5 import ( 6 "testing" 7 8 "github.com/demonoid81/moby/daemon/config" 9 "gotest.tools/v3/assert" 10 is "gotest.tools/v3/assert/cmp" 11 "gotest.tools/v3/fs" 12 ) 13 14 func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) { 15 content := `{"log-opts": {"max-size": "1k"}}` 16 tempFile := fs.NewFile(t, "config", fs.WithContent(content)) 17 defer tempFile.Remove() 18 19 opts := defaultOptions(t, tempFile.Path()) 20 opts.Debug = true 21 opts.LogLevel = "info" 22 assert.Check(t, opts.flags.Set("selinux-enabled", "true")) 23 24 loadedConfig, err := loadDaemonCliConfig(opts) 25 assert.NilError(t, err) 26 assert.Assert(t, loadedConfig != nil) 27 28 assert.Check(t, loadedConfig.Debug) 29 assert.Check(t, is.Equal("info", loadedConfig.LogLevel)) 30 assert.Check(t, loadedConfig.EnableSelinuxSupport) 31 assert.Check(t, is.Equal("json-file", loadedConfig.LogConfig.Type)) 32 assert.Check(t, is.Equal("1k", loadedConfig.LogConfig.Config["max-size"])) 33 } 34 35 func TestLoadDaemonConfigWithNetwork(t *testing.T) { 36 content := `{"bip": "127.0.0.2", "ip": "127.0.0.1"}` 37 tempFile := fs.NewFile(t, "config", fs.WithContent(content)) 38 defer tempFile.Remove() 39 40 opts := defaultOptions(t, tempFile.Path()) 41 loadedConfig, err := loadDaemonCliConfig(opts) 42 assert.NilError(t, err) 43 assert.Assert(t, loadedConfig != nil) 44 45 assert.Check(t, is.Equal("127.0.0.2", loadedConfig.IP)) 46 assert.Check(t, is.Equal("127.0.0.1", loadedConfig.DefaultIP.String())) 47 } 48 49 func TestLoadDaemonConfigWithMapOptions(t *testing.T) { 50 content := `{ 51 "cluster-store-opts": {"kv.cacertfile": "/var/lib/docker/discovery_certs/ca.pem"}, 52 "log-opts": {"tag": "test"} 53 }` 54 tempFile := fs.NewFile(t, "config", fs.WithContent(content)) 55 defer tempFile.Remove() 56 57 opts := defaultOptions(t, tempFile.Path()) 58 loadedConfig, err := loadDaemonCliConfig(opts) 59 assert.NilError(t, err) 60 assert.Assert(t, loadedConfig != nil) 61 assert.Check(t, loadedConfig.ClusterOpts != nil) 62 63 expectedPath := "/var/lib/docker/discovery_certs/ca.pem" 64 assert.Check(t, is.Equal(expectedPath, loadedConfig.ClusterOpts["kv.cacertfile"])) 65 assert.Check(t, loadedConfig.LogConfig.Config != nil) 66 assert.Check(t, is.Equal("test", loadedConfig.LogConfig.Config["tag"])) 67 } 68 69 func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) { 70 content := `{ "userland-proxy": false }` 71 tempFile := fs.NewFile(t, "config", fs.WithContent(content)) 72 defer tempFile.Remove() 73 74 opts := defaultOptions(t, tempFile.Path()) 75 loadedConfig, err := loadDaemonCliConfig(opts) 76 assert.NilError(t, err) 77 assert.Assert(t, loadedConfig != nil) 78 79 assert.Check(t, !loadedConfig.EnableUserlandProxy) 80 81 // make sure reloading doesn't generate configuration 82 // conflicts after normalizing boolean values. 83 reload := func(reloadedConfig *config.Config) { 84 assert.Check(t, !reloadedConfig.EnableUserlandProxy) 85 } 86 assert.Check(t, config.Reload(opts.configFile, opts.flags, reload)) 87 } 88 89 func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) { 90 tempFile := fs.NewFile(t, "config", fs.WithContent(`{}`)) 91 defer tempFile.Remove() 92 93 opts := defaultOptions(t, tempFile.Path()) 94 loadedConfig, err := loadDaemonCliConfig(opts) 95 assert.NilError(t, err) 96 assert.Assert(t, loadedConfig != nil) 97 98 assert.Check(t, loadedConfig.EnableUserlandProxy) 99 }