1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/cli/flags/common_test.go
Daniel Nephin abe32de6b4 Trim quotes from TLS flags.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2017-01-03 15:58:41 -05:00

42 lines
1.2 KiB
Go

package flags
import (
"path/filepath"
"testing"
cliconfig "github.com/docker/docker/cli/config"
"github.com/docker/docker/pkg/testutil/assert"
"github.com/spf13/pflag"
)
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\"",
})
assert.NilError(t, err)
assert.Equal(t, opts.TLSOptions.CAFile, "/foo/cafile")
assert.Equal(t, opts.TLSOptions.CertFile, "/foo/cert")
assert.Equal(t, opts.TLSOptions.KeyFile, "/foo/key")
}
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{})
assert.NilError(t, err)
assert.Equal(t, opts.TLSOptions.CAFile, defaultPath("ca.pem"))
assert.Equal(t, opts.TLSOptions.CertFile, defaultPath("cert.pem"))
assert.Equal(t, opts.TLSOptions.KeyFile, defaultPath("key.pem"))
}