mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
test: add test for PatchNode when error happend
Signed-off-by: haoyun <yun.hao@daocloud.io>
This commit is contained in:
parent
1af8a8c026
commit
a600e31c55
@ -26,18 +26,20 @@ import (
|
|||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/client-go/kubernetes/fake"
|
"k8s.io/client-go/kubernetes/fake"
|
||||||
core "k8s.io/client-go/testing"
|
core "k8s.io/client-go/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
const configMapName = "configmap"
|
const configMapName = "configmap"
|
||||||
|
|
||||||
func TestPatchNodeNonErrorCases(t *testing.T) {
|
func TestPatchNode(t *testing.T) {
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
name string
|
name string
|
||||||
lookupName string
|
lookupName string
|
||||||
node v1.Node
|
node v1.Node
|
||||||
success bool
|
success bool
|
||||||
|
fakeError error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "simple update",
|
name: "simple update",
|
||||||
@ -65,6 +67,30 @@ func TestPatchNodeNonErrorCases(t *testing.T) {
|
|||||||
},
|
},
|
||||||
success: false,
|
success: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "patch node when timeout",
|
||||||
|
lookupName: "testnode",
|
||||||
|
node: v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "testnode",
|
||||||
|
Labels: map[string]string{v1.LabelHostname: ""},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
success: false,
|
||||||
|
fakeError: apierrors.NewTimeoutError("fake timeout", -1),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "patch node when conflict",
|
||||||
|
lookupName: "testnode",
|
||||||
|
node: v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "testnode",
|
||||||
|
Labels: map[string]string{v1.LabelHostname: ""},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
success: false,
|
||||||
|
fakeError: apierrors.NewConflict(schema.GroupResource{}, "fake conflict", nil),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testcases {
|
for _, tc := range testcases {
|
||||||
@ -74,6 +100,11 @@ func TestPatchNodeNonErrorCases(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create node to fake client: %v", err)
|
t.Fatalf("failed to create node to fake client: %v", err)
|
||||||
}
|
}
|
||||||
|
if tc.fakeError != nil {
|
||||||
|
client.PrependReactor("patch", "nodes", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
||||||
|
return true, nil, tc.fakeError
|
||||||
|
})
|
||||||
|
}
|
||||||
var lastError error
|
var lastError error
|
||||||
conditionFunction := PatchNodeOnce(client, tc.lookupName, func(node *v1.Node) {
|
conditionFunction := PatchNodeOnce(client, tc.lookupName, func(node *v1.Node) {
|
||||||
node.Annotations = map[string]string{
|
node.Annotations = map[string]string{
|
||||||
|
Loading…
Reference in New Issue
Block a user