github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/cmd/dockerd/options_test.go (about) 1 package main 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 cliconfig "github.com/demonoid81/moby/cli/config" 8 "github.com/demonoid81/moby/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 }