2017-01-03 15:58:41 -05:00
|
|
|
package flags
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
cliconfig "github.com/docker/cli/cli/config"
|
2017-01-03 15:58:41 -05:00
|
|
|
"github.com/spf13/pflag"
|
2018-06-08 12:24:26 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
2017-01-03 15:58:41 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommonOptionsInstallFlags(t *testing.T) {
|
|
|
|
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
|
|
|
opts := NewCommonOptions()
|
|
|
|
opts.InstallFlags(flags)
|
|
|
|
|
|
|
|
err := flags.Parse([]string{
|
|
|
|
"--tlscacert=\"/foo/cafile\"",
|
|
|
|
"--tlscert=\"/foo/cert\"",
|
|
|
|
"--tlskey=\"/foo/key\"",
|
|
|
|
})
|
2018-03-06 14:44:13 -05:00
|
|
|
assert.NilError(t, err)
|
2018-03-05 18:53:52 -05:00
|
|
|
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 {
|
|
|
|
return filepath.Join(cliconfig.Dir(), filename)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
|
|
|
|
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
|
|
|
opts := NewCommonOptions()
|
|
|
|
opts.InstallFlags(flags)
|
|
|
|
|
|
|
|
err := flags.Parse([]string{})
|
2018-03-06 14:44:13 -05:00
|
|
|
assert.NilError(t, err)
|
2018-03-05 18:53:52 -05:00
|
|
|
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
|
|
|
}
|