This non-standard handling for these options was added in [moby@e4c1f07] and [moby@abe32de] to work around a regression in Docker 1.13 that caused `docker-machine` to fail. Preserving quotes in such cases is expected (and standard behavior), but versions of Docker before 1.13 used a custom "mflag" package for flag parsing, and that package contained custom handling for quotes (added in [moby@0e9c40e]). Given that Docker Machine reached EOL a long time ago and other options, such as `docker context`, have been added to configure the CLI to connect to a specific host (with corresponding TLS configuration), we can remove the special handling for these flags, as it's inconsistent with all other flags, and not worth maintaining for a tool that no longer exists. [moby@e4c1f07]:e4c1f07729[moby@abe32de]:abe32de6b4[moby@0e9c40e]:0e9c40eb82Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package flags
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/docker/cli/cli/config"
|
|
"github.com/spf13/pflag"
|
|
"gotest.tools/v3/assert"
|
|
is "gotest.tools/v3/assert/cmp"
|
|
)
|
|
|
|
func TestClientOptionsInstallFlags(t *testing.T) {
|
|
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
|
opts := NewClientOptions()
|
|
opts.InstallFlags(flags)
|
|
|
|
err := flags.Parse([]string{
|
|
"--tlscacert=/foo/cafile",
|
|
"--tlscert=/foo/cert",
|
|
"--tlskey=/foo/key",
|
|
})
|
|
assert.NilError(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"))
|
|
}
|
|
|
|
func defaultPath(filename string) string {
|
|
return filepath.Join(config.Dir(), filename)
|
|
}
|
|
|
|
func TestClientOptionsInstallFlagsWithDefaults(t *testing.T) {
|
|
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
|
opts := NewClientOptions()
|
|
opts.InstallFlags(flags)
|
|
|
|
err := flags.Parse([]string{})
|
|
assert.NilError(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))
|
|
}
|