github.com/gravitational/moby@v1.13.1/daemon/config_unix_test.go (about) 1 // +build !windows 2 3 package daemon 4 5 import ( 6 "io/ioutil" 7 "testing" 8 ) 9 10 func TestDaemonConfigurationMerge(t *testing.T) { 11 f, err := ioutil.TempFile("", "docker-config-") 12 if err != nil { 13 t.Fatal(err) 14 } 15 16 configFile := f.Name() 17 18 f.Write([]byte(` 19 { 20 "debug": true, 21 "default-ulimits": { 22 "nofile": { 23 "Name": "nofile", 24 "Hard": 2048, 25 "Soft": 1024 26 } 27 }, 28 "log-opts": { 29 "tag": "test_tag" 30 } 31 }`)) 32 33 f.Close() 34 35 c := &Config{ 36 CommonConfig: CommonConfig{ 37 AutoRestart: true, 38 LogConfig: LogConfig{ 39 Type: "syslog", 40 Config: map[string]string{"tag": "test"}, 41 }, 42 }, 43 } 44 45 cc, err := MergeDaemonConfigurations(c, nil, configFile) 46 if err != nil { 47 t.Fatal(err) 48 } 49 if !cc.Debug { 50 t.Fatalf("expected %v, got %v\n", true, cc.Debug) 51 } 52 if !cc.AutoRestart { 53 t.Fatalf("expected %v, got %v\n", true, cc.AutoRestart) 54 } 55 if cc.LogConfig.Type != "syslog" { 56 t.Fatalf("expected syslog config, got %q\n", cc.LogConfig) 57 } 58 59 if configValue, OK := cc.LogConfig.Config["tag"]; !OK { 60 t.Fatal("expected syslog config attributes, got nil\n") 61 } else { 62 if configValue != "test_tag" { 63 t.Fatalf("expected syslog config attributes 'tag=test_tag', got 'tag=%s'\n", configValue) 64 } 65 } 66 67 if cc.Ulimits == nil { 68 t.Fatal("expected default ulimit config, got nil\n") 69 } else { 70 if _, OK := cc.Ulimits["nofile"]; OK { 71 if cc.Ulimits["nofile"].Name != "nofile" || 72 cc.Ulimits["nofile"].Hard != 2048 || 73 cc.Ulimits["nofile"].Soft != 1024 { 74 t.Fatalf("expected default ulimit name, hard and soft are nofile, 2048, 1024, got %s, %d, %d\n", cc.Ulimits["nofile"].Name, cc.Ulimits["nofile"].Hard, cc.Ulimits["nofile"].Soft) 75 } 76 } else { 77 t.Fatal("expected default ulimit name nofile, got nil\n") 78 } 79 } 80 }