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:
parent
baf5b1c999
commit
bd48fd4c16
|
@ -250,15 +250,15 @@ func processJSONPathInput(jsonPathInput []string) (string, string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
if len(jsonPathInput) > 1 {
|
if len(jsonPathInput) == 1 {
|
||||||
jsonPathValue := jsonPathInput[1]
|
|
||||||
if jsonPathValue == "" {
|
|
||||||
return "", "", errors.New("jsonpath wait value cannot be empty")
|
|
||||||
}
|
|
||||||
return relaxedJSONPathExp, strings.Trim(jsonPathValue, `'"`), nil
|
|
||||||
}
|
|
||||||
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
|
// ResourceLocation holds the location of a resource
|
||||||
type ResourceLocation struct {
|
type ResourceLocation struct {
|
||||||
|
|
|
@ -1556,13 +1556,13 @@ func TestWaitForJSONPathBadConditionParsing(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "undefined value",
|
name: "undefined value",
|
||||||
condition: "jsonpath={.metadata.name}=",
|
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 {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
_, err := conditionFuncFor(test.condition, io.Discard)
|
_, err := conditionFuncFor(test.condition, io.Discard)
|
||||||
if err == nil {
|
if err == nil && test.expectedErr != "" {
|
||||||
t.Fatalf("expected %q, got empty", test.expectedErr)
|
t.Fatalf("expected %q, got empty", test.expectedErr)
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), test.expectedErr) {
|
if !strings.Contains(err.Error(), test.expectedErr) {
|
||||||
|
|
Loading…
Reference in New Issue