github.com/docker/engine@v22.0.0-20211208180946-d456264580cf+incompatible/daemon/config/config_windows_test.go (about)

     1  package config // import "github.com/docker/docker/daemon/config"
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/docker/docker/opts"
     8  	"github.com/spf13/pflag"
     9  	"gotest.tools/v3/assert"
    10  	is "gotest.tools/v3/assert/cmp"
    11  )
    12  
    13  func TestDaemonConfigurationMerge(t *testing.T) {
    14  	f, err := os.CreateTemp("", "docker-config-")
    15  	if err != nil {
    16  		t.Fatal(err)
    17  	}
    18  
    19  	configFile := f.Name()
    20  
    21  	f.Write([]byte(`
    22  		{
    23  			"debug": true,
    24  			"log-opts": {
    25  				"tag": "test_tag"
    26  			}
    27  		}`))
    28  
    29  	f.Close()
    30  
    31  	c := &Config{
    32  		CommonConfig: CommonConfig{
    33  			AutoRestart: true,
    34  			LogConfig: LogConfig{
    35  				Type:   "syslog",
    36  				Config: map[string]string{"tag": "test"},
    37  			},
    38  		},
    39  	}
    40  
    41  	flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
    42  	var debug bool
    43  	flags.BoolVarP(&debug, "debug", "D", false, "")
    44  	flags.Var(opts.NewNamedMapOpts("log-opts", nil, nil), "log-opt", "")
    45  
    46  	cc, err := MergeDaemonConfigurations(c, flags, configFile)
    47  	assert.NilError(t, err)
    48  
    49  	assert.Check(t, cc.Debug)
    50  	assert.Check(t, cc.AutoRestart)
    51  
    52  	expectedLogConfig := LogConfig{
    53  		Type:   "syslog",
    54  		Config: map[string]string{"tag": "test_tag"},
    55  	}
    56  
    57  	assert.Check(t, is.DeepEqual(expectedLogConfig, cc.LogConfig))
    58  }