2017-01-03 15:58:41 -05:00
|
|
|
package flags
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2022-03-04 07:24:28 -05:00
|
|
|
"github.com/docker/cli/cli/config"
|
2017-01-03 15:58:41 -05:00
|
|
|
"github.com/spf13/pflag"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2017-01-03 15:58:41 -05:00
|
|
|
)
|
|
|
|
|
2022-11-04 06:58:11 -04:00
|
|
|
func TestClientOptionsInstallFlags(t *testing.T) {
|
2017-01-03 15:58:41 -05:00
|
|
|
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
2022-11-04 06:58:11 -04:00
|
|
|
opts := NewClientOptions()
|
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-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 {
|
2022-03-04 07:24:28 -05:00
|
|
|
return filepath.Join(config.Dir(), filename)
|
2017-01-03 15:58:41 -05:00
|
|
|
}
|
|
|
|
|
2022-11-04 06:58:11 -04:00
|
|
|
func TestClientOptionsInstallFlagsWithDefaults(t *testing.T) {
|
2017-01-03 15:58:41 -05:00
|
|
|
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
2022-11-04 06:58:11 -04:00
|
|
|
opts := NewClientOptions()
|
2017-01-03 15:58:41 -05:00
|
|
|
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
|
|
|
}
|