Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
5337bc22
Commit
5337bc22
authored
May 10, 2016
by
Hongchao Deng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
etcd_watcher: test for ensuring delete event have latest index
parent
fcf63a6c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
etcd_watcher_test.go
pkg/storage/etcd/etcd_watcher_test.go
+68
-0
No files found.
pkg/storage/etcd/etcd_watcher_test.go
View file @
5337bc22
...
@@ -220,6 +220,74 @@ func TestWatchInterpretation_ResponseBadData(t *testing.T) {
...
@@ -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
)
{
func
TestWatch
(
t
*
testing
.
T
)
{
codec
:=
testapi
.
Default
.
Codec
()
codec
:=
testapi
.
Default
.
Codec
()
server
:=
etcdtesting
.
NewEtcdTestClientServer
(
t
)
server
:=
etcdtesting
.
NewEtcdTestClientServer
(
t
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment