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.
This commit is contained in:
Martin Atkins 2019-08-29 18:00:45 -07:00
parent bc9756882e
commit c4076fe6a2
1 changed files with 11 additions and 0 deletions

View File

@ -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.