mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Delete fails on notfound errors.
If deleting multiple resources, command will continue on error and report not found resources at the end.
This commit is contained in:
@@ -18,13 +18,16 @@ package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
func TestDeleteObjectByTuple(t *testing.T) {
|
||||
@@ -120,6 +123,34 @@ func TestDeleteObject(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteObjectNotFound(t *testing.T) {
|
||||
f, tf, codec := NewAPIFactory()
|
||||
tf.Printer = &testPrinter{}
|
||||
tf.Client = &client.FakeRESTClient{
|
||||
Codec: codec,
|
||||
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
||||
switch p, m := req.URL.Path, req.Method; {
|
||||
case p == "/namespaces/test/replicationcontrollers/redis-master" && m == "DELETE":
|
||||
return &http.Response{StatusCode: 404, Body: stringBody("")}, nil
|
||||
default:
|
||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||
return nil, nil
|
||||
}
|
||||
}),
|
||||
}
|
||||
tf.Namespace = "test"
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
|
||||
cmd := NewCmdDelete(f, buf)
|
||||
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.json")
|
||||
cmd.Flags().Set("cascade", "false")
|
||||
filenames := cmd.Flags().Lookup("filename").Value.(*util.StringList)
|
||||
err := RunDelete(f, buf, cmd, []string{}, *filenames)
|
||||
if err == nil || !errors.IsNotFound(err) {
|
||||
t.Errorf("unexpected error: expected NotFound, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteObjectIgnoreNotFound(t *testing.T) {
|
||||
f, tf, codec := NewAPIFactory()
|
||||
tf.Printer = &testPrinter{}
|
||||
@@ -141,6 +172,7 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) {
|
||||
cmd := NewCmdDelete(f, buf)
|
||||
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.json")
|
||||
cmd.Flags().Set("cascade", "false")
|
||||
cmd.Flags().Set("ignore-not-found", "true")
|
||||
cmd.Run(cmd, []string{})
|
||||
|
||||
if buf.String() != "" {
|
||||
@@ -181,7 +213,7 @@ func TestDeleteMultipleObject(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteMultipleObjectIgnoreMissing(t *testing.T) {
|
||||
func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) {
|
||||
_, svc, _ := testData()
|
||||
|
||||
f, tf, codec := NewAPIFactory()
|
||||
@@ -207,7 +239,12 @@ func TestDeleteMultipleObjectIgnoreMissing(t *testing.T) {
|
||||
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.json")
|
||||
cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.json")
|
||||
cmd.Flags().Set("cascade", "false")
|
||||
cmd.Run(cmd, []string{})
|
||||
filenames := cmd.Flags().Lookup("filename").Value.(*util.StringList)
|
||||
fmt.Printf("filenames: %v\n", filenames)
|
||||
err := RunDelete(f, buf, cmd, []string{}, *filenames)
|
||||
if err == nil || !errors.IsNotFound(err) {
|
||||
t.Errorf("unexpected error: expected NotFound, got %v", err)
|
||||
}
|
||||
|
||||
if buf.String() != "services/frontend\n" {
|
||||
t.Errorf("unexpected output: %s", buf.String())
|
||||
|
||||
Reference in New Issue
Block a user