mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-26 12:02:34 +00:00
add/update tests
Move negative check for testing "not patched" output to test-cmd-util.sh as exiting with code 1 was causing patch_test.go to fail when the error was expected as part of the test.
This commit is contained in:
parent
dfef8574cf
commit
de21640573
@ -694,6 +694,10 @@ run_pod_tests() {
|
|||||||
## Patch can modify a local object
|
## Patch can modify a local object
|
||||||
kubectl patch --local -f pkg/kubectl/validation/testdata/v1/validPod.yaml --patch='{"spec": {"restartPolicy":"Never"}}' -o jsonpath='{.spec.restartPolicy}' | grep -q "Never"
|
kubectl patch --local -f pkg/kubectl/validation/testdata/v1/validPod.yaml --patch='{"spec": {"restartPolicy":"Never"}}' -o jsonpath='{.spec.restartPolicy}' | grep -q "Never"
|
||||||
|
|
||||||
|
## Patch fails with error message "not patched" and exit code 1
|
||||||
|
output_message=$(! kubectl patch "${kube_flags[@]}" pod valid-pod -p='{"spec":{"replicas":7}}' 2>&1)
|
||||||
|
kube::test::if_has_string "${output_message}" 'not patched'
|
||||||
|
|
||||||
## Patch pod can change image
|
## Patch pod can change image
|
||||||
# Command
|
# Command
|
||||||
kubectl patch "${kube_flags[@]}" pod valid-pod --record -p='{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "nginx"}]}}'
|
kubectl patch "${kube_flags[@]}" pod valid-pod --record -p='{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "nginx"}]}}'
|
||||||
|
@ -38,7 +38,14 @@ func TestPatchObject(t *testing.T) {
|
|||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == "/namespaces/test/services/frontend" && (m == "PATCH" || m == "GET"):
|
case p == "/namespaces/test/services/frontend" && (m == "PATCH" || m == "GET"):
|
||||||
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &svc.Items[0])}, nil
|
obj := svc.Items[0]
|
||||||
|
|
||||||
|
// ensure patched object reflects successful
|
||||||
|
// patch edits from the client
|
||||||
|
if m == "PATCH" {
|
||||||
|
obj.Spec.Type = "NodePort"
|
||||||
|
}
|
||||||
|
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &obj)}, nil
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@ -116,18 +123,6 @@ func TestPatchNoop(t *testing.T) {
|
|||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
|
|
||||||
// No-op
|
|
||||||
{
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
cmd := NewCmdPatch(f, buf)
|
|
||||||
cmd.Flags().Set("namespace", "test")
|
|
||||||
cmd.Flags().Set("patch", `{}`)
|
|
||||||
cmd.Run(cmd, []string{"services", "frontend"})
|
|
||||||
if buf.String() != "service \"baz\" not patched\n" {
|
|
||||||
t.Errorf("unexpected output: %s", buf.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Patched
|
// Patched
|
||||||
{
|
{
|
||||||
patchObject = patchObject.DeepCopy()
|
patchObject = patchObject.DeepCopy()
|
||||||
|
Loading…
Reference in New Issue
Block a user