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:
Ian Campbell 2019-01-10 15:49:06 +00:00
parent 20c19830a9
commit eab40a5974
2 changed files with 19 additions and 0 deletions

View File

@ -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) {

View File

@ -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)
}