github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/cmd/dockerd/daemon_unix_test.go (about)

     1  // +build !windows,!solaris
     2  
     3  // TODO: Create new file for Solaris which tests config parameters
     4  // as described in daemon/config_solaris.go
     5  
     6  package main
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/docker/docker/daemon/config"
    12  	"github.com/docker/docker/pkg/testutil/tempfile"
    13  	"github.com/stretchr/testify/assert"
    14  	"github.com/stretchr/testify/require"
    15  )
    16  
    17  func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
    18  	content := `{"log-opts": {"max-size": "1k"}}`
    19  	tempFile := tempfile.NewTempFile(t, "config", content)
    20  	defer tempFile.Remove()
    21  
    22  	opts := defaultOptions(tempFile.Name())
    23  	opts.Debug = true
    24  	opts.LogLevel = "info"
    25  	assert.NoError(t, opts.flags.Set("selinux-enabled", "true"))
    26  
    27  	loadedConfig, err := loadDaemonCliConfig(opts)
    28  	require.NoError(t, err)
    29  	require.NotNil(t, loadedConfig)
    30  
    31  	assert.True(t, loadedConfig.Debug)
    32  	assert.Equal(t, "info", loadedConfig.LogLevel)
    33  	assert.True(t, loadedConfig.EnableSelinuxSupport)
    34  	assert.Equal(t, "json-file", loadedConfig.LogConfig.Type)
    35  	assert.Equal(t, "1k", loadedConfig.LogConfig.Config["max-size"])
    36  }
    37  
    38  func TestLoadDaemonConfigWithNetwork(t *testing.T) {
    39  	content := `{"bip": "127.0.0.2", "ip": "127.0.0.1"}`
    40  	tempFile := tempfile.NewTempFile(t, "config", content)
    41  	defer tempFile.Remove()
    42  
    43  	opts := defaultOptions(tempFile.Name())
    44  	loadedConfig, err := loadDaemonCliConfig(opts)
    45  	require.NoError(t, err)
    46  	require.NotNil(t, loadedConfig)
    47  
    48  	assert.Equal(t, "127.0.0.2", loadedConfig.IP)
    49  	assert.Equal(t, "127.0.0.1", loadedConfig.DefaultIP.String())
    50  }
    51  
    52  func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
    53  	content := `{
    54  		"cluster-store-opts": {"kv.cacertfile": "/var/lib/docker/discovery_certs/ca.pem"},
    55  		"log-opts": {"tag": "test"}
    56  }`
    57  	tempFile := tempfile.NewTempFile(t, "config", content)
    58  	defer tempFile.Remove()
    59  
    60  	opts := defaultOptions(tempFile.Name())
    61  	loadedConfig, err := loadDaemonCliConfig(opts)
    62  	require.NoError(t, err)
    63  	require.NotNil(t, loadedConfig)
    64  	assert.NotNil(t, loadedConfig.ClusterOpts)
    65  
    66  	expectedPath := "/var/lib/docker/discovery_certs/ca.pem"
    67  	assert.Equal(t, expectedPath, loadedConfig.ClusterOpts["kv.cacertfile"])
    68  	assert.NotNil(t, loadedConfig.LogConfig.Config)
    69  	assert.Equal(t, "test", loadedConfig.LogConfig.Config["tag"])
    70  }
    71  
    72  func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
    73  	content := `{ "userland-proxy": false }`
    74  	tempFile := tempfile.NewTempFile(t, "config", content)
    75  	defer tempFile.Remove()
    76  
    77  	opts := defaultOptions(tempFile.Name())
    78  	loadedConfig, err := loadDaemonCliConfig(opts)
    79  	require.NoError(t, err)
    80  	require.NotNil(t, loadedConfig)
    81  
    82  	assert.False(t, loadedConfig.EnableUserlandProxy)
    83  
    84  	// make sure reloading doesn't generate configuration
    85  	// conflicts after normalizing boolean values.
    86  	reload := func(reloadedConfig *config.Config) {
    87  		assert.False(t, reloadedConfig.EnableUserlandProxy)
    88  	}
    89  	assert.NoError(t, config.Reload(opts.configFile, opts.flags, reload))
    90  }
    91  
    92  func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
    93  	tempFile := tempfile.NewTempFile(t, "config", `{}`)
    94  	defer tempFile.Remove()
    95  
    96  	opts := defaultOptions(tempFile.Name())
    97  	loadedConfig, err := loadDaemonCliConfig(opts)
    98  	require.NoError(t, err)
    99  	require.NotNil(t, loadedConfig)
   100  
   101  	assert.True(t, loadedConfig.EnableUserlandProxy)
   102  }
   103  
   104  func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
   105  	content := `{"disable-legacy-registry": true}`
   106  	tempFile := tempfile.NewTempFile(t, "config", content)
   107  	defer tempFile.Remove()
   108  
   109  	opts := defaultOptions(tempFile.Name())
   110  	loadedConfig, err := loadDaemonCliConfig(opts)
   111  	require.NoError(t, err)
   112  	require.NotNil(t, loadedConfig)
   113  	assert.True(t, loadedConfig.V2Only)
   114  }