github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/cmd/dockerd/options_test.go (about)

     1  package main
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  
     7  	cliconfig "github.com/docker/docker/cli/config"
     8  	"github.com/docker/docker/daemon/config"
     9  	"github.com/spf13/pflag"
    10  	"gotest.tools/v3/assert"
    11  	is "gotest.tools/v3/assert/cmp"
    12  )
    13  
    14  func TestCommonOptionsInstallFlags(t *testing.T) {
    15  	flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
    16  	opts := newDaemonOptions(&config.Config{})
    17  	opts.InstallFlags(flags)
    18  
    19  	err := flags.Parse([]string{
    20  		"--tlscacert=\"/foo/cafile\"",
    21  		"--tlscert=\"/foo/cert\"",
    22  		"--tlskey=\"/foo/key\"",
    23  	})
    24  	assert.Check(t, err)
    25  	assert.Check(t, is.Equal("/foo/cafile", opts.TLSOptions.CAFile))
    26  	assert.Check(t, is.Equal("/foo/cert", opts.TLSOptions.CertFile))
    27  	assert.Check(t, is.Equal(opts.TLSOptions.KeyFile, "/foo/key"))
    28  }
    29  
    30  func defaultPath(filename string) string {
    31  	return filepath.Join(cliconfig.Dir(), filename)
    32  }
    33  
    34  func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
    35  	flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
    36  	opts := newDaemonOptions(&config.Config{})
    37  	opts.InstallFlags(flags)
    38  
    39  	err := flags.Parse([]string{})
    40  	assert.Check(t, err)
    41  	assert.Check(t, is.Equal(defaultPath("ca.pem"), opts.TLSOptions.CAFile))
    42  	assert.Check(t, is.Equal(defaultPath("cert.pem"), opts.TLSOptions.CertFile))
    43  	assert.Check(t, is.Equal(defaultPath("key.pem"), opts.TLSOptions.KeyFile))
    44  }