github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/daemon/config/config_common_unix_test.go (about)

     1  // +build !windows
     2  
     3  package config // import "github.com/docker/docker/daemon/config"
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/docker/docker/api/types"
     9  )
    10  
    11  func TestCommonUnixValidateConfigurationErrors(t *testing.T) {
    12  	testCases := []struct {
    13  		config *Config
    14  	}{
    15  		// Can't override the stock runtime
    16  		{
    17  			config: &Config{
    18  				CommonUnixConfig: CommonUnixConfig{
    19  					Runtimes: map[string]types.Runtime{
    20  						StockRuntimeName: {},
    21  					},
    22  				},
    23  			},
    24  		},
    25  		// Default runtime should be present in runtimes
    26  		{
    27  			config: &Config{
    28  				CommonUnixConfig: CommonUnixConfig{
    29  					Runtimes: map[string]types.Runtime{
    30  						"foo": {},
    31  					},
    32  					DefaultRuntime: "bar",
    33  				},
    34  			},
    35  		},
    36  	}
    37  	for _, tc := range testCases {
    38  		err := Validate(tc.config)
    39  		if err == nil {
    40  			t.Fatalf("expected error, got nil for config %v", tc.config)
    41  		}
    42  	}
    43  }
    44  
    45  func TestCommonUnixGetInitPath(t *testing.T) {
    46  	testCases := []struct {
    47  		config           *Config
    48  		expectedInitPath string
    49  	}{
    50  		{
    51  			config: &Config{
    52  				InitPath: "some-init-path",
    53  			},
    54  			expectedInitPath: "some-init-path",
    55  		},
    56  		{
    57  			config: &Config{
    58  				CommonUnixConfig: CommonUnixConfig{
    59  					DefaultInitBinary: "foo-init-bin",
    60  				},
    61  			},
    62  			expectedInitPath: "foo-init-bin",
    63  		},
    64  		{
    65  			config: &Config{
    66  				InitPath: "init-path-A",
    67  				CommonUnixConfig: CommonUnixConfig{
    68  					DefaultInitBinary: "init-path-B",
    69  				},
    70  			},
    71  			expectedInitPath: "init-path-A",
    72  		},
    73  		{
    74  			config:           &Config{},
    75  			expectedInitPath: "docker-init",
    76  		},
    77  	}
    78  	for _, tc := range testCases {
    79  		initPath := tc.config.GetInitPath()
    80  		if initPath != tc.expectedInitPath {
    81  			t.Fatalf("expected initPath to be %v, got %v", tc.expectedInitPath, initPath)
    82  		}
    83  	}
    84  }