mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
etcd_watcher: test for ensuring delete event have latest index
This commit is contained in:
parent
fcf63a6c4b
commit
5337bc220a
@ -220,6 +220,74 @@ func TestWatchInterpretation_ResponseBadData(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendResultDeleteEventHaveLatestIndex(t *testing.T) {
|
||||
codec := testapi.Default.Codec()
|
||||
filter := func(obj runtime.Object) bool {
|
||||
return obj.(*api.Pod).Name != "bar"
|
||||
}
|
||||
w := newEtcdWatcher(false, false, nil, filter, codec, versioner, nil, &fakeEtcdCache{})
|
||||
|
||||
eventChan := make(chan watch.Event, 1)
|
||||
w.emit = func(e watch.Event) {
|
||||
eventChan <- e
|
||||
}
|
||||
|
||||
fooPod := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
|
||||
barPod := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "bar"}}
|
||||
fooBytes, err := runtime.Encode(codec, fooPod)
|
||||
if err != nil {
|
||||
t.Fatalf("Encode failed: %v", err)
|
||||
}
|
||||
barBytes, err := runtime.Encode(codec, barPod)
|
||||
if err != nil {
|
||||
t.Fatalf("Encode failed: %v", err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
response *etcd.Response
|
||||
expRV string
|
||||
}{{ // Delete event
|
||||
response: &etcd.Response{
|
||||
Action: EtcdDelete,
|
||||
Node: &etcd.Node{
|
||||
ModifiedIndex: 2,
|
||||
},
|
||||
PrevNode: &etcd.Node{
|
||||
Value: string(fooBytes),
|
||||
ModifiedIndex: 1,
|
||||
},
|
||||
},
|
||||
expRV: "2",
|
||||
}, { // Modify event with uninterested data
|
||||
response: &etcd.Response{
|
||||
Action: EtcdSet,
|
||||
Node: &etcd.Node{
|
||||
Value: string(barBytes),
|
||||
ModifiedIndex: 2,
|
||||
},
|
||||
PrevNode: &etcd.Node{
|
||||
Value: string(fooBytes),
|
||||
ModifiedIndex: 1,
|
||||
},
|
||||
},
|
||||
expRV: "2",
|
||||
}}
|
||||
|
||||
for i, tt := range tests {
|
||||
w.sendResult(tt.response)
|
||||
ev := <-eventChan
|
||||
if ev.Type != watch.Deleted {
|
||||
t.Errorf("#%d: event type want=Deleted, get=%s", i, ev.Type)
|
||||
return
|
||||
}
|
||||
rv := ev.Object.(*api.Pod).ResourceVersion
|
||||
if rv != tt.expRV {
|
||||
t.Errorf("#%d: resource version want=%s, get=%s", i, tt.expRV, rv)
|
||||
}
|
||||
}
|
||||
w.Stop()
|
||||
}
|
||||
|
||||
func TestWatch(t *testing.T) {
|
||||
codec := testapi.Default.Codec()
|
||||
server := etcdtesting.NewEtcdTestClientServer(t)
|
||||
|
Loading…
Reference in New Issue
Block a user