github.com/ssdev-go/moby@v17.12.1-ce-rc2+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  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestCommonOptionsInstallFlags(t *testing.T) {
    14  	flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
    15  	opts := newDaemonOptions(&config.Config{})
    16  	opts.InstallFlags(flags)
    17  
    18  	err := flags.Parse([]string{
    19  		"--tlscacert=\"/foo/cafile\"",
    20  		"--tlscert=\"/foo/cert\"",
    21  		"--tlskey=\"/foo/key\"",
    22  	})
    23  	assert.NoError(t, err)
    24  	assert.Equal(t, "/foo/cafile", opts.TLSOptions.CAFile)
    25  	assert.Equal(t, "/foo/cert", opts.TLSOptions.CertFile)
    26  	assert.Equal(t, opts.TLSOptions.KeyFile, "/foo/key")
    27  }
    28  
    29  func defaultPath(filename string) string {
    30  	return filepath.Join(cliconfig.Dir(), filename)
    31  }
    32  
    33  func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
    34  	flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
    35  	opts := newDaemonOptions(&config.Config{})
    36  	opts.InstallFlags(flags)
    37  
    38  	err := flags.Parse([]string{})
    39  	assert.NoError(t, err)
    40  	assert.Equal(t, defaultPath("ca.pem"), opts.TLSOptions.CAFile)
    41  	assert.Equal(t, defaultPath("cert.pem"), opts.TLSOptions.CertFile)
    42  	assert.Equal(t, defaultPath("key.pem"), opts.TLSOptions.KeyFile)
    43  }