From c4076fe6a2e98abe68c3a341cfd58ddc873e6e58 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 29 Aug 2019 18:00:45 -0700 Subject: [PATCH] command/cliconfig: EmptyCredentialsSourceForTests A more convenient interface to get a throwaway empty credentials source for use in tests, which doesn't interact at all with the real CLI configuration directory. --- command/cliconfig/credentials.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/command/cliconfig/credentials.go b/command/cliconfig/credentials.go index f38087e00..d23ede4b6 100644 --- a/command/cliconfig/credentials.go +++ b/command/cliconfig/credentials.go @@ -64,6 +64,17 @@ func (c *Config) CredentialsSource(helperPlugins pluginDiscovery.PluginMetaSet) return c.credentialsSource(helperType, helper, credentialsFilePath), nil } +// EmptyCredentialsSourceForTests constructs a CredentialsSource with +// no credentials pre-loaded and which writes new credentials to a file +// at the given path. +// +// As the name suggests, this function is here only for testing and should not +// be used in normal application code. +func EmptyCredentialsSourceForTests(credentialsFilePath string) *CredentialsSource { + cfg := &Config{} + return cfg.credentialsSource("", nil, credentialsFilePath) +} + // credentialsSource is an internal factory for the credentials source which // allows overriding the credentials file path, which allows setting it to // a temporary file location when testing.