2017-06-01 16:34:31 -04:00
|
|
|
package main
|
2017-01-03 15:58:41 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2017-06-01 16:34:31 -04:00
|
|
|
cliconfig "github.com/docker/docker/cli/config"
|
|
|
|
"github.com/docker/docker/daemon/config"
|
2017-01-03 15:58:41 -05:00
|
|
|
"github.com/spf13/pflag"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2017-01-03 15:58:41 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommonOptionsInstallFlags(t *testing.T) {
|
|
|
|
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
2017-06-01 16:34:31 -04:00
|
|
|
opts := newDaemonOptions(&config.Config{})
|
2017-01-03 15:58:41 -05:00
|
|
|
opts.InstallFlags(flags)
|
|
|
|
|
|
|
|
err := flags.Parse([]string{
|
|
|
|
"--tlscacert=\"/foo/cafile\"",
|
|
|
|
"--tlscert=\"/foo/cert\"",
|
|
|
|
"--tlskey=\"/foo/key\"",
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, err)
|
|
|
|
assert.Check(t, is.Equal("/foo/cafile", opts.TLSOptions.CAFile))
|
|
|
|
assert.Check(t, is.Equal("/foo/cert", opts.TLSOptions.CertFile))
|
|
|
|
assert.Check(t, is.Equal(opts.TLSOptions.KeyFile, "/foo/key"))
|
2017-01-03 15:58:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultPath(filename string) string {
|
2017-06-01 16:34:31 -04:00
|
|
|
return filepath.Join(cliconfig.Dir(), filename)
|
2017-01-03 15:58:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
|
|
|
|
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
2017-06-01 16:34:31 -04:00
|
|
|
opts := newDaemonOptions(&config.Config{})
|
2017-01-03 15:58:41 -05:00
|
|
|
opts.InstallFlags(flags)
|
|
|
|
|
|
|
|
err := flags.Parse([]string{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, err)
|
|
|
|
assert.Check(t, is.Equal(defaultPath("ca.pem"), opts.TLSOptions.CAFile))
|
|
|
|
assert.Check(t, is.Equal(defaultPath("cert.pem"), opts.TLSOptions.CertFile))
|
|
|
|
assert.Check(t, is.Equal(defaultPath("key.pem"), opts.TLSOptions.KeyFile))
|
2017-01-03 15:58:41 -05:00
|
|
|
}
|