chore: address review feedback

add integration test to wait for json without value
refactor JSON condition value parsing and validating
adjusting test to reflect the error message refactoring

Kubernetes-commit: dbdd861ea366af50fb74983426587dad7222cb89
This commit is contained in:
minherz 2023-06-29 00:36:07 -07:00 committed by Kubernetes Publisher
parent baf5b1c999
commit bd48fd4c16
2 changed files with 9 additions and 9 deletions

View File

@ -250,14 +250,14 @@ func processJSONPathInput(jsonPathInput []string) (string, string, error) {
if err != nil {
return "", "", err
}
if len(jsonPathInput) > 1 {
jsonPathValue := jsonPathInput[1]
if jsonPathValue == "" {
return "", "", errors.New("jsonpath wait value cannot be empty")
}
return relaxedJSONPathExp, strings.Trim(jsonPathValue, `'"`), nil
if len(jsonPathInput) == 1 {
return relaxedJSONPathExp, "", nil
}
return relaxedJSONPathExp, "", nil
jsonPathValue := strings.Trim(jsonPathInput[1], `'"`)
if jsonPathValue == "" {
return "", "", errors.New("jsonpath wait has to have a value after equal sign, like --for=jsonpath='{.status.readyReplicas}'=3")
}
return relaxedJSONPathExp, jsonPathValue, nil
}
// ResourceLocation holds the location of a resource

View File

@ -1556,13 +1556,13 @@ func TestWaitForJSONPathBadConditionParsing(t *testing.T) {
{
name: "undefined value",
condition: "jsonpath={.metadata.name}=",
expectedErr: "jsonpath wait value cannot be empty",
expectedErr: "jsonpath wait has to have a value after equal sign, like --for=jsonpath='{.status.readyReplicas}'=3",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, err := conditionFuncFor(test.condition, io.Discard)
if err == nil {
if err == nil && test.expectedErr != "" {
t.Fatalf("expected %q, got empty", test.expectedErr)
}
if !strings.Contains(err.Error(), test.expectedErr) {