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
438052c4
Commit
438052c4
authored
Mar 05, 2015
by
Mike Danese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix variable shadowing bug in etcd_tools.go
parent
54b2b47c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
5 deletions
+20
-5
etcd_tools.go
pkg/tools/etcd_tools.go
+4
-5
etcd_tools_test.go
pkg/tools/etcd_tools_test.go
+11
-0
fake_etcd_client.go
pkg/tools/fake_etcd_client.go
+5
-0
No files found.
pkg/tools/etcd_tools.go
View file @
438052c4
...
...
@@ -329,15 +329,14 @@ func (h *EtcdHelper) SetObj(key string, obj, out runtime.Object, ttl uint64) err
create
:=
true
if
h
.
ResourceVersioner
!=
nil
{
version
,
err
:=
h
.
ResourceVersioner
.
ResourceVersion
(
obj
)
if
err
==
nil
&&
version
!=
0
{
if
version
,
err
:=
h
.
ResourceVersioner
.
ResourceVersion
(
obj
);
err
==
nil
&&
version
!=
0
{
create
=
false
response
,
err
=
h
.
Client
.
CompareAndSwap
(
key
,
string
(
data
),
ttl
,
""
,
version
)
if
err
!=
nil
{
return
err
}
}
}
if
err
!=
nil
{
return
err
}
if
create
{
// Create will fail if a key already exists.
response
,
err
=
h
.
Client
.
Create
(
key
,
string
(
data
),
ttl
)
...
...
pkg/tools/etcd_tools_test.go
View file @
438052c4
...
...
@@ -414,6 +414,17 @@ func TestSetObj(t *testing.T) {
}
}
func
TestSetObjFailCAS
(
t
*
testing
.
T
)
{
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
ResourceVersion
:
"1"
}}
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
.
CasErr
=
fakeClient
.
NewError
(
123
)
helper
:=
EtcdHelper
{
fakeClient
,
testapi
.
Codec
(),
versioner
}
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
,
nil
,
5
)
if
err
==
nil
{
t
.
Errorf
(
"Expecting error."
)
}
}
func
TestSetObjWithVersion
(
t
*
testing
.
T
)
{
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
ResourceVersion
:
"1"
}}
fakeClient
:=
NewFakeEtcdClient
(
t
)
...
...
pkg/tools/fake_etcd_client.go
View file @
438052c4
...
...
@@ -47,6 +47,7 @@ type FakeEtcdClient struct {
expectNotFoundGetSet
map
[
string
]
struct
{}
sync
.
Mutex
Err
error
CasErr
error
t
TestLogger
Ix
int
TestIndex
bool
...
...
@@ -225,6 +226,10 @@ func (f *FakeEtcdClient) CompareAndSwap(key, value string, ttl uint64, prevValue
f
.
t
.
Logf
(
"c&s: returning err %v"
,
f
.
Err
)
return
nil
,
f
.
Err
}
if
f
.
CasErr
!=
nil
{
f
.
t
.
Logf
(
"c&s: returning err %v"
,
f
.
CasErr
)
return
nil
,
f
.
CasErr
}
if
!
f
.
TestIndex
{
f
.
t
.
Errorf
(
"Enable TestIndex for test involving CompareAndSwap"
)
...
...
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