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"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2017-01-03 15:58:41 -05:00
|
|
|
"github.com/spf13/pflag"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
}
|