github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/daemon/config/config_windows_test.go (about)

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