MCPcopy
hub / github.com/kubernetes-sigs/kwok / TestInformerWatch

Function TestInformerWatch

pkg/utils/informer/informer_test.go:88–186  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestInformerWatch(t *testing.T) {
89 now := time.Unix(1, 0)
90
91 fakeClient := fake.NewClientset(
92 &coordinationv1.Lease{
93 ObjectMeta: metav1.ObjectMeta{
94 Name: "lease0",
95 Namespace: "default",
96 },
97 Spec: coordinationv1.LeaseSpec{
98 HolderIdentity: new("lease0"),
99 RenewTime: new(metav1.NewMicroTime(now)),
100 },
101 },
102 )
103 cli := fakeClient.CoordinationV1().Leases("default")
104 informer := NewInformer[*coordinationv1.Lease, *coordinationv1.LeaseList](cli)
105
106 ctx := t.Context()
107
108 events := make(chan Event[*coordinationv1.Lease], 100)
109 _ = informer.Watch(ctx, Option{}, events)
110
111 time.Sleep(1 * time.Second)
112
113 _, _ = cli.Create(ctx,
114 &coordinationv1.Lease{
115 ObjectMeta: metav1.ObjectMeta{
116 Name: "lease1",
117 },
118 Spec: coordinationv1.LeaseSpec{
119 HolderIdentity: new("lease1"),
120 RenewTime: new(metav1.NewMicroTime(now)),
121 },
122 },
123 metav1.CreateOptions{},
124 )
125
126 time.Sleep(1 * time.Second)
127
128 _, _ = cli.Update(ctx,
129 &coordinationv1.Lease{
130 ObjectMeta: metav1.ObjectMeta{
131 Name: "lease1",
132 },
133 Spec: coordinationv1.LeaseSpec{
134 HolderIdentity: new("lease1"),
135 RenewTime: new(metav1.NewMicroTime(now.Add(1 * time.Second))),
136 },
137 },
138 metav1.UpdateOptions{},
139 )
140
141 time.Sleep(1 * time.Second)
142
143 _ = cli.Delete(ctx,
144 "lease1",
145 metav1.DeleteOptions{},

Callers

nothing calls this directly

Calls 8

SleepMethod · 0.80
ErrorMethod · 0.80
WatchMethod · 0.65
CreateMethod · 0.65
UpdateMethod · 0.65
AddMethod · 0.65
DeleteMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected