2017-06-01 20:34:31 +00:00
|
|
|
package main
|
2017-01-03 20:58:41 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2017-06-01 20:34:31 +00:00
|
|
|
cliconfig "github.com/docker/docker/cli/config"
|
|
|
|
"github.com/docker/docker/daemon/config"
|
2017-01-03 20:58:41 +00:00
|
|
|
"github.com/spf13/pflag"
|
2018-06-11 13:32:11 +00:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
2017-01-03 20:58:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommonOptionsInstallFlags(t *testing.T) {
|
|
|
|
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
2017-06-01 20:34:31 +00:00
|
|
|
opts := newDaemonOptions(&config.Config{})
|
2017-01-03 20:58:41 +00:00
|
|
|
opts.InstallFlags(flags)
|
|
|
|
|
|
|
|
err := flags.Parse([]string{
|
|
|
|
"--tlscacert=\"/foo/cafile\"",
|
|
|
|
"--tlscert=\"/foo/cert\"",
|
|
|
|
"--tlskey=\"/foo/key\"",
|
|
|
|
})
|
2018-03-13 19:28:34 +00: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 20:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultPath(filename string) string {
|
2017-06-01 20:34:31 +00:00
|
|
|
return filepath.Join(cliconfig.Dir(), filename)
|
2017-01-03 20:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
|
|
|
|
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
2017-06-01 20:34:31 +00:00
|
|
|
opts := newDaemonOptions(&config.Config{})
|
2017-01-03 20:58:41 +00:00
|
|
|
opts.InstallFlags(flags)
|
|
|
|
|
|
|
|
err := flags.Parse([]string{})
|
2018-03-13 19:28:34 +00: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 20:58:41 +00:00
|
|
|
}
|