Default config/secret target to source name

When using advanced syntax for setting config and secret values, default
the target value to the source value when the user does not specify a
target.

Signed-off-by: Nick Adcock <nick.adcock@docker.com>
This commit is contained in:
Nick Adcock 2020-01-07 13:11:53 +00:00
parent 4c2d7b7f70
commit 9698b7a374
4 changed files with 8 additions and 0 deletions

View File

@ -72,6 +72,9 @@ func (o *ConfigOpt) Set(value string) error {
if options.ConfigName == "" {
return fmt.Errorf("source is required")
}
if options.File.Name == "" {
options.File.Name = options.ConfigName
}
o.values = append(o.values, options)
return nil

View File

@ -33,6 +33,7 @@ func TestConfigOptionsSource(t *testing.T) {
assert.Assert(t, is.Len(reqs, 1))
req := reqs[0]
assert.Check(t, is.Equal("foo", req.ConfigName))
assert.Check(t, is.Equal("foo", req.File.Name))
}
func TestConfigOptionsSourceTarget(t *testing.T) {

View File

@ -72,6 +72,9 @@ func (o *SecretOpt) Set(value string) error {
if options.SecretName == "" {
return fmt.Errorf("source is required")
}
if options.File.Name == "" {
options.File.Name = options.SecretName
}
o.values = append(o.values, options)
return nil

View File

@ -33,6 +33,7 @@ func TestSecretOptionsSource(t *testing.T) {
assert.Assert(t, is.Len(reqs, 1))
req := reqs[0]
assert.Check(t, is.Equal("foo", req.SecretName))
assert.Check(t, is.Equal("foo", req.File.Name))
}
func TestSecretOptionsSourceTarget(t *testing.T) {