mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
add .status.observedGeneration tests & update names
This commit is contained in:
parent
44aff99175
commit
bca0ddeba0
@ -791,7 +791,7 @@ func TestWaitForCondition(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "times out due to observedGeneration",
|
name: "times out due to stale .status.conditions[0].observedGeneration",
|
||||||
infos: []*resource.Info{
|
infos: []*resource.Info{
|
||||||
{
|
{
|
||||||
Mapping: &meta.RESTMapping{
|
Mapping: &meta.RESTMapping{
|
||||||
@ -827,7 +827,7 @@ func TestWaitForCondition(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "handles watch observedGeneration change",
|
name: "handles watch .status.conditions[0].observedGeneration change",
|
||||||
infos: []*resource.Info{
|
infos: []*resource.Info{
|
||||||
{
|
{
|
||||||
Mapping: &meta.RESTMapping{
|
Mapping: &meta.RESTMapping{
|
||||||
@ -854,6 +854,88 @@ func TestWaitForCondition(t *testing.T) {
|
|||||||
},
|
},
|
||||||
timeout: 10 * time.Second,
|
timeout: 10 * time.Second,
|
||||||
|
|
||||||
|
validateActions: func(t *testing.T, actions []clienttesting.Action) {
|
||||||
|
if len(actions) != 2 {
|
||||||
|
t.Fatal(spew.Sdump(actions))
|
||||||
|
}
|
||||||
|
if !actions[0].Matches("list", "theresource") || actions[0].(clienttesting.ListAction).GetListRestrictions().Fields.String() != "metadata.name=name-foo" {
|
||||||
|
t.Error(spew.Sdump(actions))
|
||||||
|
}
|
||||||
|
if !actions[1].Matches("watch", "theresource") {
|
||||||
|
t.Error(spew.Sdump(actions))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "times out due to stale .status.observedGeneration",
|
||||||
|
infos: []*resource.Info{
|
||||||
|
{
|
||||||
|
Mapping: &meta.RESTMapping{
|
||||||
|
Resource: schema.GroupVersionResource{Group: "group", Version: "version", Resource: "theresource"},
|
||||||
|
},
|
||||||
|
Name: "name-foo",
|
||||||
|
Namespace: "ns-foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fakeClient: func() *dynamicfakeclient.FakeDynamicClient {
|
||||||
|
fakeClient := dynamicfakeclient.NewSimpleDynamicClientWithCustomListKinds(scheme, listMapping)
|
||||||
|
fakeClient.PrependReactor("list", "theresource", func(action clienttesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||||
|
instance := addCondition(
|
||||||
|
newUnstructuredWithGeneration("group/version", "TheKind", "ns-foo", "name-foo", 2),
|
||||||
|
"the-condition", "status-value")
|
||||||
|
unstructured.SetNestedField(instance.Object, int64(1), "status", "observedGeneration")
|
||||||
|
return true, instance, nil
|
||||||
|
})
|
||||||
|
return fakeClient
|
||||||
|
},
|
||||||
|
timeout: 1 * time.Second,
|
||||||
|
|
||||||
|
expectedErr: "timed out waiting for the condition on theresource/name-foo",
|
||||||
|
validateActions: func(t *testing.T, actions []clienttesting.Action) {
|
||||||
|
if len(actions) != 2 {
|
||||||
|
t.Fatal(spew.Sdump(actions))
|
||||||
|
}
|
||||||
|
if !actions[0].Matches("list", "theresource") || actions[0].(clienttesting.ListAction).GetListRestrictions().Fields.String() != "metadata.name=name-foo" {
|
||||||
|
t.Error(spew.Sdump(actions))
|
||||||
|
}
|
||||||
|
if !actions[1].Matches("watch", "theresource") {
|
||||||
|
t.Error(spew.Sdump(actions))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "handles watch .status.observedGeneration change",
|
||||||
|
infos: []*resource.Info{
|
||||||
|
{
|
||||||
|
Mapping: &meta.RESTMapping{
|
||||||
|
Resource: schema.GroupVersionResource{Group: "group", Version: "version", Resource: "theresource"},
|
||||||
|
},
|
||||||
|
Name: "name-foo",
|
||||||
|
Namespace: "ns-foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fakeClient: func() *dynamicfakeclient.FakeDynamicClient {
|
||||||
|
fakeClient := dynamicfakeclient.NewSimpleDynamicClientWithCustomListKinds(scheme, listMapping)
|
||||||
|
fakeClient.PrependReactor("list", "theresource", func(action clienttesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||||
|
instance := addCondition(
|
||||||
|
newUnstructuredWithGeneration("group/version", "TheKind", "ns-foo", "name-foo", 2),
|
||||||
|
"the-condition", "status-value")
|
||||||
|
unstructured.SetNestedField(instance.Object, int64(1), "status", "observedGeneration")
|
||||||
|
return true, newUnstructuredList(instance), nil
|
||||||
|
})
|
||||||
|
fakeClient.PrependWatchReactor("theresource", func(action clienttesting.Action) (handled bool, ret watch.Interface, err error) {
|
||||||
|
instance := addCondition(
|
||||||
|
newUnstructuredWithGeneration("group/version", "TheKind", "ns-foo", "name-foo", 2),
|
||||||
|
"the-condition", "status-value")
|
||||||
|
unstructured.SetNestedField(instance.Object, int64(2), "status", "observedGeneration")
|
||||||
|
fakeWatch := watch.NewRaceFreeFake()
|
||||||
|
fakeWatch.Action(watch.Modified, instance)
|
||||||
|
return true, fakeWatch, nil
|
||||||
|
})
|
||||||
|
return fakeClient
|
||||||
|
},
|
||||||
|
timeout: 10 * time.Second,
|
||||||
|
|
||||||
validateActions: func(t *testing.T, actions []clienttesting.Action) {
|
validateActions: func(t *testing.T, actions []clienttesting.Action) {
|
||||||
if len(actions) != 2 {
|
if len(actions) != 2 {
|
||||||
t.Fatal(spew.Sdump(actions))
|
t.Fatal(spew.Sdump(actions))
|
||||||
|
Loading…
Reference in New Issue
Block a user