From f820766f6ac57188d96c9ca377f2b4627e90da28 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Thu, 16 May 2019 14:52:37 +0100 Subject: [PATCH] Export `DefaultContextStoreConfig()` and `ResolveDefaultContext()` These are needed by any dynamically registered (via `RegisterDefaultStoreEndpoints`) endpoint type to write a useful/sensible unit test. Signed-off-by: Ian Campbell --- cli/command/cli.go | 11 ++++++----- cli/command/defaultcontextstore.go | 4 ++-- cli/command/defaultcontextstore_test.go | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cli/command/cli.go b/cli/command/cli.go index 5abc54e0fc..8c0e690fab 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -214,7 +214,7 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize cli.contextStore = &ContextStoreWithDefault{ Store: baseContextStore, Resolver: func() (*DefaultContext, error) { - return resolveDefaultContext(opts.Common, cli.ConfigFile(), cli.contextStoreConfig, cli.Err()) + return ResolveDefaultContext(opts.Common, cli.ConfigFile(), cli.contextStoreConfig, cli.Err()) }, } cli.currentContext, err = resolveContextName(opts.Common, cli.configFile, cli.contextStore) @@ -259,11 +259,11 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize // NewAPIClientFromFlags creates a new APIClient from command line flags func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.ConfigFile) (client.APIClient, error) { - storeConfig := defaultContextStoreConfig() + storeConfig := DefaultContextStoreConfig() store := &ContextStoreWithDefault{ Store: store.New(cliconfig.ContextStoreDir(), storeConfig), Resolver: func() (*DefaultContext, error) { - return resolveDefaultContext(opts, configFile, storeConfig, ioutil.Discard) + return ResolveDefaultContext(opts, configFile, storeConfig, ioutil.Discard) }, } contextName, err := resolveContextName(opts, configFile, store) @@ -454,7 +454,7 @@ func NewDockerCli(ops ...DockerCliOption) (*DockerCli, error) { WithContentTrustFromEnv(), WithContainerizedClient(containerizedengine.NewClient), } - cli.contextStoreConfig = defaultContextStoreConfig() + cli.contextStoreConfig = DefaultContextStoreConfig() ops = append(defaultOps, ops...) if err := cli.Apply(ops...); err != nil { return nil, err @@ -540,7 +540,8 @@ func RegisterDefaultStoreEndpoints(ep ...store.NamedTypeGetter) { defaultStoreEndpoints = append(defaultStoreEndpoints, ep...) } -func defaultContextStoreConfig() store.Config { +// DefaultContextStoreConfig returns a new store.Config with the default set of endpoints configured. +func DefaultContextStoreConfig() store.Config { return store.NewConfig( func() interface{} { return &DockerContext{} }, defaultStoreEndpoints..., diff --git a/cli/command/defaultcontextstore.go b/cli/command/defaultcontextstore.go index 1489990947..f270b06c2f 100644 --- a/cli/command/defaultcontextstore.go +++ b/cli/command/defaultcontextstore.go @@ -43,8 +43,8 @@ type EndpointDefaultResolver interface { ResolveDefault() (interface{}, *store.EndpointTLSData) } -// resolveDefaultContext creates a Metadata for the current CLI invocation parameters -func resolveDefaultContext(opts *cliflags.CommonOptions, config *configfile.ConfigFile, storeconfig store.Config, stderr io.Writer) (*DefaultContext, error) { +// ResolveDefaultContext creates a Metadata for the current CLI invocation parameters +func ResolveDefaultContext(opts *cliflags.CommonOptions, config *configfile.ConfigFile, storeconfig store.Config, stderr io.Writer) (*DefaultContext, error) { stackOrchestrator, err := GetStackOrchestrator("", "", config.StackOrchestrator, stderr) if err != nil { return nil, err diff --git a/cli/command/defaultcontextstore_test.go b/cli/command/defaultcontextstore_test.go index 493d0f4fe5..d50c9a1d07 100644 --- a/cli/command/defaultcontextstore_test.go +++ b/cli/command/defaultcontextstore_test.go @@ -67,12 +67,12 @@ func TestDefaultContextInitializer(t *testing.T) { cli.configFile = &configfile.ConfigFile{ StackOrchestrator: "all", } - ctx, err := resolveDefaultContext(&cliflags.CommonOptions{ + ctx, err := ResolveDefaultContext(&cliflags.CommonOptions{ TLS: true, TLSOptions: &tlsconfig.Options{ CAFile: "./testdata/ca.pem", }, - }, cli.ConfigFile(), defaultContextStoreConfig(), cli.Err()) + }, cli.ConfigFile(), DefaultContextStoreConfig(), cli.Err()) assert.NilError(t, err) assert.Equal(t, "default", ctx.Meta.Name) assert.Equal(t, OrchestratorAll, ctx.Meta.Metadata.(DockerContext).StackOrchestrator)