mirror of https://github.com/docker/cli.git
fix the error message in Substitute function
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
This commit is contained in:
parent
e33bc48752
commit
5d8ce59a25
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
var delimiter = "\\$"
|
||||
var substitution = "[_a-z][_a-z0-9]*(?::?[-?][^}]+)?"
|
||||
var substitution = "[_a-z][_a-z0-9]*(?::?[-?][^}]*)?"
|
||||
|
||||
var patternString = fmt.Sprintf(
|
||||
"%s(?i:(?P<escaped>%s)|(?P<named>%s)|{(?P<braced>%s)}|(?P<invalid>))",
|
||||
|
@ -75,7 +75,9 @@ func Substitute(template string, mapping Mapping) (string, error) {
|
|||
name, errorMessage := partition(substitution, ":?")
|
||||
value, ok := mapping(name)
|
||||
if !ok || value == "" {
|
||||
err = &InvalidTemplateError{Template: errorMessage}
|
||||
err = &InvalidTemplateError{
|
||||
Template: fmt.Sprintf("required variable %s is missing a value: %s", name, errorMessage),
|
||||
}
|
||||
return ""
|
||||
}
|
||||
return value
|
||||
|
@ -84,7 +86,9 @@ func Substitute(template string, mapping Mapping) (string, error) {
|
|||
name, errorMessage := partition(substitution, "?")
|
||||
value, ok := mapping(name)
|
||||
if !ok {
|
||||
err = &InvalidTemplateError{Template: errorMessage}
|
||||
err = &InvalidTemplateError{
|
||||
Template: fmt.Sprintf("required variable %s is missing a value: %s", name, errorMessage),
|
||||
}
|
||||
return ""
|
||||
}
|
||||
return value
|
||||
|
|
|
@ -97,23 +97,23 @@ func TestMandatoryVariableErrors(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
template: "not ok ${UNSET_VAR:?Mandatory Variable Unset}",
|
||||
expectedError: "Mandatory Variable Unset",
|
||||
expectedError: "required variable UNSET_VAR is missing a value: Mandatory Variable Unset",
|
||||
},
|
||||
{
|
||||
template: "not ok ${BAR:?Mandatory Variable Empty}",
|
||||
expectedError: "Mandatory Variable Empty",
|
||||
expectedError: "required variable BAR is missing a value: Mandatory Variable Empty",
|
||||
},
|
||||
{
|
||||
template: "not ok ${UNSET_VAR:?}",
|
||||
expectedError: "",
|
||||
expectedError: "required variable UNSET_VAR is missing a value",
|
||||
},
|
||||
{
|
||||
template: "not ok ${UNSET_VAR?Mandatory Variable Unset",
|
||||
expectedError: "Mandatory Variable Unset",
|
||||
template: "not ok ${UNSET_VAR?Mandatory Variable Unset}",
|
||||
expectedError: "required variable UNSET_VAR is missing a value: Mandatory Variable Unset",
|
||||
},
|
||||
{
|
||||
template: "not ok ${UNSET_VAR?}",
|
||||
expectedError: "",
|
||||
expectedError: "required variable UNSET_VAR is missing a value",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue