@@ -12,6 +12,53 @@ import (
1212 "github.com/docker/docker/pkg/mflag"
1313)
1414
15+ func TestLoadDaemonCliConfigWithDaemonFlags (t * testing.T ) {
16+ c := & daemon.Config {}
17+ common := & cli.CommonFlags {
18+ Debug : true ,
19+ LogLevel : "info" ,
20+ }
21+
22+ f , err := ioutil .TempFile ("" , "docker-config-" )
23+ if err != nil {
24+ t .Fatal (err )
25+ }
26+
27+ configFile := f .Name ()
28+ f .Write ([]byte (`{"log-opts": {"max-size": "1k"}}` ))
29+ f .Close ()
30+
31+ flags := mflag .NewFlagSet ("test" , mflag .ContinueOnError )
32+ flags .String ([]string {daemonConfigFileFlag }, "" , "" )
33+ flags .BoolVar (& c .EnableSelinuxSupport , []string {"-selinux-enabled" }, true , "" )
34+ flags .StringVar (& c .LogConfig .Type , []string {"-log-driver" }, "json-file" , "" )
35+ flags .Var (opts .NewNamedMapOpts ("log-opts" , c .LogConfig .Config , nil ), []string {"-log-opt" }, "" )
36+ flags .Set (daemonConfigFileFlag , configFile )
37+
38+ loadedConfig , err := loadDaemonCliConfig (c , flags , common , configFile )
39+ if err != nil {
40+ t .Fatal (err )
41+ }
42+ if loadedConfig == nil {
43+ t .Fatalf ("expected configuration %v, got nil" , c )
44+ }
45+ if ! loadedConfig .Debug {
46+ t .Fatalf ("expected debug mode, got false" )
47+ }
48+ if loadedConfig .LogLevel != "info" {
49+ t .Fatalf ("expected info log level, got %v" , loadedConfig .LogLevel )
50+ }
51+ if ! loadedConfig .EnableSelinuxSupport {
52+ t .Fatalf ("expected enabled selinux support, got disabled" )
53+ }
54+ if loadedConfig .LogConfig .Type != "json-file" {
55+ t .Fatalf ("expected LogConfig type json-file, got %v" , loadedConfig .LogConfig .Type )
56+ }
57+ if maxSize := loadedConfig .LogConfig .Config ["max-size" ]; maxSize != "1k" {
58+ t .Fatalf ("expected log max-size `1k`, got %s" , maxSize )
59+ }
60+ }
61+
1562func TestLoadDaemonConfigWithNetwork (t * testing.T ) {
1663 c := & daemon.Config {}
1764 common := & cli.CommonFlags {}
0 commit comments