mirror of https://github.com/docker/cli.git
cli/config: Add a helper to resolve a file within the config dir
Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
parent
20c19830a9
commit
eab40a5974
|
@ -46,6 +46,11 @@ func SetDir(dir string) {
|
|||
configDir = dir
|
||||
}
|
||||
|
||||
// Path returns the path to a file relative to the config dir
|
||||
func Path(p ...string) string {
|
||||
return filepath.Join(append([]string{Dir()}, p...)...)
|
||||
}
|
||||
|
||||
// LegacyLoadFromReader is a convenience function that creates a ConfigFile object from
|
||||
// a non-nested reader
|
||||
func LegacyLoadFromReader(configData io.Reader) (*configfile.ConfigFile, error) {
|
||||
|
|
|
@ -548,3 +548,17 @@ func TestLoadDefaultConfigFile(t *testing.T) {
|
|||
|
||||
assert.Check(t, is.DeepEqual(expected, configFile))
|
||||
}
|
||||
|
||||
func TestConfigPath(t *testing.T) {
|
||||
oldDir := Dir()
|
||||
|
||||
SetDir("dummy1")
|
||||
f1 := Path("a", "b")
|
||||
assert.Equal(t, f1, filepath.Join("dummy1", "a", "b"))
|
||||
|
||||
SetDir("dummy2")
|
||||
f2 := Path("c", "d")
|
||||
assert.Equal(t, f2, filepath.Join("dummy2", "c", "d"))
|
||||
|
||||
SetDir(oldDir)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue