mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 19:23:40 +00:00
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
This commit is contained in:
parent
a5c4fbe979
commit
dbdd861ea3
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -94,6 +94,21 @@ EOF
|
||||
# Clean deployment
|
||||
kubectl delete deployment dtest
|
||||
|
||||
# create test data
|
||||
kubectl create deployment test-3 --image=busybox
|
||||
|
||||
# wait with jsonpath without value to succeed
|
||||
set +o errexit
|
||||
# Command: Wait with jsonpath without value
|
||||
output_message=$(kubectl wait --for=jsonpath='{.status.replicas}' deploy/test-3 2>&1)
|
||||
set -o errexit
|
||||
|
||||
# Post-Condition: Wait succeed
|
||||
kube::test::if_has_string "${output_message}" 'deployment.apps/test-3 condition met'
|
||||
|
||||
# Clean deployment
|
||||
kubectl delete deployment test-3
|
||||
|
||||
set +o nounset
|
||||
set +o errexit
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user