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
61de4fc3
Commit
61de4fc3
authored
Aug 20, 2015
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring of create etcd tests.
parent
9ad982ef
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
369 additions
and
470 deletions
+369
-470
resttest.go
pkg/api/rest/resttest/resttest.go
+67
-8
etcd_test.go
pkg/registry/controller/etcd/etcd_test.go
+24
-117
etcd_test.go
pkg/registry/daemon/etcd/etcd_test.go
+30
-131
etcd_test.go
pkg/registry/endpoint/etcd/etcd_test.go
+6
-0
etcd_test.go
pkg/registry/horizontalpodautoscaler/etcd/etcd_test.go
+6
-0
etcd_test.go
pkg/registry/limitrange/etcd/etcd_test.go
+21
-75
etcd_test.go
pkg/registry/minion/etcd/etcd_test.go
+6
-0
etcd_test.go
pkg/registry/namespace/etcd/etcd_test.go
+6
-0
etcd_test.go
pkg/registry/persistentvolume/etcd/etcd_test.go
+6
-0
etcd_test.go
pkg/registry/persistentvolumeclaim/etcd/etcd_test.go
+6
-0
etcd_test.go
pkg/registry/pod/etcd/etcd_test.go
+6
-19
etcd_test.go
pkg/registry/podtemplate/etcd/etcd_test.go
+7
-0
etcd.go
pkg/registry/registrytest/etcd.go
+41
-2
etcd_test.go
pkg/registry/resourcequota/etcd/etcd_test.go
+6
-32
etcd_test.go
pkg/registry/secret/etcd/etcd_test.go
+7
-0
etcd_test.go
pkg/registry/service/etcd/etcd_test.go
+88
-0
rest_test.go
pkg/registry/service/rest_test.go
+4
-60
etcd_test.go
pkg/registry/serviceaccount/etcd/etcd_test.go
+7
-0
etcd_test.go
pkg/registry/thirdpartyresource/etcd/etcd_test.go
+25
-26
No files found.
pkg/api/rest/resttest/resttest.go
View file @
61de4fc3
...
@@ -36,9 +36,10 @@ import (
...
@@ -36,9 +36,10 @@ import (
type
Tester
struct
{
type
Tester
struct
{
*
testing
.
T
*
testing
.
T
storage
rest
.
Storage
storage
rest
.
Storage
storageError
injectErrorFunc
storageError
injectErrorFunc
clusterScope
bool
clusterScope
bool
generatesName
bool
}
}
type
injectErrorFunc
func
(
err
error
)
type
injectErrorFunc
func
(
err
error
)
...
@@ -62,6 +63,11 @@ func (t *Tester) ClusterScope() *Tester {
...
@@ -62,6 +63,11 @@ func (t *Tester) ClusterScope() *Tester {
return
t
return
t
}
}
func
(
t
*
Tester
)
GeneratesName
()
*
Tester
{
t
.
generatesName
=
true
return
t
}
// TestNamespace returns the namespace that will be used when creating contexts.
// TestNamespace returns the namespace that will be used when creating contexts.
// Returns NamespaceNone for cluster-scoped objects.
// Returns NamespaceNone for cluster-scoped objects.
func
(
t
*
Tester
)
TestNamespace
()
string
{
func
(
t
*
Tester
)
TestNamespace
()
string
{
...
@@ -96,14 +102,20 @@ func copyOrDie(obj runtime.Object) runtime.Object {
...
@@ -96,14 +102,20 @@ func copyOrDie(obj runtime.Object) runtime.Object {
return
out
return
out
}
}
type
AssignFunc
func
(
objs
[]
runtime
.
Object
)
[]
runtime
.
Object
type
AssignFunc
func
([]
runtime
.
Object
)
[]
runtime
.
Object
type
SetRVFunc
func
(
resourceVersion
uint64
)
type
GetFunc
func
(
api
.
Context
,
runtime
.
Object
)
(
runtime
.
Object
,
error
)
type
SetFunc
func
(
api
.
Context
,
runtime
.
Object
)
error
type
SetRVFunc
func
(
uint64
)
// Test creating an object.
// Test creating an object.
func
(
t
*
Tester
)
TestCreate
(
valid
runtime
.
Object
,
invalid
...
runtime
.
Object
)
{
func
(
t
*
Tester
)
TestCreate
(
valid
runtime
.
Object
,
setFn
SetFunc
,
getFn
GetFunc
,
invalid
...
runtime
.
Object
)
{
t
.
testCreateHasMetadata
(
copyOrDie
(
valid
))
t
.
testCreateHasMetadata
(
copyOrDie
(
valid
))
t
.
testCreateGeneratesName
(
copyOrDie
(
valid
))
if
!
t
.
generatesName
{
t
.
testCreateGeneratesNameReturnsServerTimeout
(
copyOrDie
(
valid
))
t
.
testCreateGeneratesName
(
copyOrDie
(
valid
))
t
.
testCreateGeneratesNameReturnsServerTimeout
(
copyOrDie
(
valid
))
}
t
.
testCreateEquals
(
copyOrDie
(
valid
),
getFn
)
t
.
testCreateAlreadyExisting
(
copyOrDie
(
valid
),
setFn
)
if
t
.
clusterScope
{
if
t
.
clusterScope
{
t
.
testCreateDiscardsObjectNamespace
(
copyOrDie
(
valid
))
t
.
testCreateDiscardsObjectNamespace
(
copyOrDie
(
valid
))
t
.
testCreateIgnoresContextNamespace
(
copyOrDie
(
valid
))
t
.
testCreateIgnoresContextNamespace
(
copyOrDie
(
valid
))
...
@@ -161,6 +173,53 @@ func (t *Tester) TestList(obj runtime.Object, assignFn AssignFunc, setRVFn SetRV
...
@@ -161,6 +173,53 @@ func (t *Tester) TestList(obj runtime.Object, assignFn AssignFunc, setRVFn SetRV
// =============================================================================
// =============================================================================
// Creation tests.
// Creation tests.
func
(
t
*
Tester
)
testCreateAlreadyExisting
(
obj
runtime
.
Object
,
setFn
SetFunc
)
{
ctx
:=
t
.
TestContext
()
foo
:=
copyOrDie
(
obj
)
fooMeta
:=
t
.
getObjectMetaOrFail
(
foo
)
fooMeta
.
Name
=
"foo1"
fooMeta
.
Namespace
=
api
.
NamespaceValue
(
ctx
)
fooMeta
.
GenerateName
=
""
if
err
:=
setFn
(
ctx
,
foo
);
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
_
,
err
:=
t
.
storage
.
(
rest
.
Creater
)
.
Create
(
ctx
,
foo
)
if
!
errors
.
IsAlreadyExists
(
err
)
{
t
.
Errorf
(
"expected already exists err, got %v"
,
err
)
}
}
func
(
t
*
Tester
)
testCreateEquals
(
obj
runtime
.
Object
,
getFn
GetFunc
)
{
ctx
:=
t
.
TestContext
()
foo
:=
copyOrDie
(
obj
)
fooMeta
:=
t
.
getObjectMetaOrFail
(
foo
)
fooMeta
.
Name
=
"foo2"
fooMeta
.
Namespace
=
api
.
NamespaceValue
(
ctx
)
fooMeta
.
GenerateName
=
""
created
,
err
:=
t
.
storage
.
(
rest
.
Creater
)
.
Create
(
ctx
,
foo
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
got
,
err
:=
getFn
(
ctx
,
foo
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
// Set resource version which might be unset in created object.
createdMeta
:=
t
.
getObjectMetaOrFail
(
created
)
gotMeta
:=
t
.
getObjectMetaOrFail
(
got
)
createdMeta
.
ResourceVersion
=
gotMeta
.
ResourceVersion
if
e
,
a
:=
created
,
got
;
!
api
.
Semantic
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"unexpected obj: %#v, expected %#v"
,
e
,
a
)
}
}
func
(
t
*
Tester
)
testCreateDiscardsObjectNamespace
(
valid
runtime
.
Object
)
{
func
(
t
*
Tester
)
testCreateDiscardsObjectNamespace
(
valid
runtime
.
Object
)
{
objectMeta
:=
t
.
getObjectMetaOrFail
(
valid
)
objectMeta
:=
t
.
getObjectMetaOrFail
(
valid
)
...
...
pkg/registry/controller/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -18,7 +18,6 @@ package etcd
...
@@ -18,7 +18,6 @@ package etcd
import
(
import
(
"strconv"
"strconv"
"strings"
"testing"
"testing"
"time"
"time"
...
@@ -87,102 +86,33 @@ var validController = api.ReplicationController{
...
@@ -87,102 +86,33 @@ var validController = api.ReplicationController{
Spec
:
validControllerSpec
,
Spec
:
validControllerSpec
,
}
}
func
TestEtcdCreateController
(
t
*
testing
.
T
)
{
func
TestCreate
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
storage
,
fakeClient
:=
newStorage
(
t
)
_
,
err
:=
storage
.
Create
(
ctx
,
&
validController
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
key
,
_
:=
storage
.
KeyFunc
(
ctx
,
validController
.
Name
)
key
=
etcdtest
.
AddPrefix
(
key
)
resp
,
err
:=
fakeClient
.
Get
(
key
,
false
,
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
var
ctrl
api
.
ReplicationController
err
=
testapi
.
Codec
()
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
ctrl
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
ctrl
.
Name
!=
"foo"
{
t
.
Errorf
(
"Unexpected controller: %#v %s"
,
ctrl
,
resp
.
Node
.
Value
)
}
}
func
TestEtcdCreateControllerAlreadyExisting
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
storage
,
fakeClient
:=
newStorage
(
t
)
storage
,
fakeClient
:=
newStorage
(
t
)
key
,
_
:=
storage
.
KeyFunc
(
ctx
,
validController
.
Name
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeClient
.
SetError
)
key
=
etcdtest
.
AddPrefix
(
key
)
test
.
TestCreate
(
fakeClient
.
Set
(
key
,
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
&
validController
),
0
)
// valid
&
api
.
ReplicationController
{
_
,
err
:=
storage
.
Create
(
ctx
,
&
validController
)
Spec
:
api
.
ReplicationControllerSpec
{
if
!
errors
.
IsAlreadyExists
(
err
)
{
Replicas
:
2
,
t
.
Errorf
(
"expected already exists err, got %#v"
,
err
)
Selector
:
map
[
string
]
string
{
"a"
:
"b"
},
}
Template
:
&
validPodTemplate
.
Template
,
}
},
func
TestEtcdCreateControllerValidates
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
storage
,
_
:=
newStorage
(
t
)
emptyName
:=
validController
emptyName
.
Name
=
""
failureCases
:=
[]
api
.
ReplicationController
{
emptyName
}
for
_
,
failureCase
:=
range
failureCases
{
c
,
err
:=
storage
.
Create
(
ctx
,
&
failureCase
)
if
c
!=
nil
{
t
.
Errorf
(
"Expected nil channel"
)
}
if
!
errors
.
IsInvalid
(
err
)
{
t
.
Errorf
(
"Expected to get an invalid resource error, got %v"
,
err
)
}
}
}
func
TestCreateControllerWithGeneratedName
(
t
*
testing
.
T
)
{
storage
,
_
:=
newStorage
(
t
)
controller
:=
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
GenerateName
:
"rc-"
,
},
},
Spec
:
api
.
ReplicationControllerSpec
{
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
Replicas
:
2
,
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
Selector
:
map
[
string
]
string
{
"a"
:
"b"
},
Template
:
&
validPodTemplate
.
Template
,
},
},
}
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
ctx
:=
api
.
NewDefaultContext
()
},
_
,
err
:=
storage
.
Create
(
ctx
,
controller
)
// invalid
if
err
!=
nil
{
&
api
.
ReplicationController
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
Spec
:
api
.
ReplicationControllerSpec
{
}
Replicas
:
2
,
if
controller
.
Name
==
"rc-"
||
!
strings
.
HasPrefix
(
controller
.
Name
,
"rc-"
)
{
Selector
:
map
[
string
]
string
{},
t
.
Errorf
(
"unexpected name: %#v"
,
controller
)
Template
:
&
validPodTemplate
.
Template
,
}
},
}
},
)
func
TestCreateControllerWithConflictingNamespace
(
t
*
testing
.
T
)
{
storage
,
_
:=
newStorage
(
t
)
controller
:=
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
,
Namespace
:
"not-default"
},
}
ctx
:=
api
.
NewDefaultContext
()
channel
,
err
:=
storage
.
Create
(
ctx
,
controller
)
if
channel
!=
nil
{
t
.
Error
(
"Expected a nil channel, but we got a value"
)
}
errSubString
:=
"namespace"
if
err
==
nil
{
t
.
Errorf
(
"Expected an error, but we didn't get one"
)
}
else
if
!
errors
.
IsBadRequest
(
err
)
||
strings
.
Index
(
err
.
Error
(),
errSubString
)
==
-
1
{
t
.
Errorf
(
"Expected a Bad Request error with the sub string '%s', got %v"
,
errSubString
,
err
)
}
}
}
func
TestEtcdControllerValidatesUpdate
(
t
*
testing
.
T
)
{
func
TestEtcdControllerValidatesUpdate
(
t
*
testing
.
T
)
{
...
@@ -553,29 +483,6 @@ func TestEtcdWatchControllersNotMatch(t *testing.T) {
...
@@ -553,29 +483,6 @@ func TestEtcdWatchControllersNotMatch(t *testing.T) {
}
}
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
storage
,
fakeClient
:=
newStorage
(
t
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeClient
.
SetError
)
test
.
TestCreate
(
// valid
&
api
.
ReplicationController
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Selector
:
map
[
string
]
string
{
"a"
:
"b"
},
Template
:
&
validPodTemplate
.
Template
,
},
},
// invalid
&
api
.
ReplicationController
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Selector
:
map
[
string
]
string
{},
Template
:
&
validPodTemplate
.
Template
,
},
},
)
}
func
TestDelete
(
t
*
testing
.
T
)
{
func
TestDelete
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
storage
,
fakeClient
:=
newStorage
(
t
)
storage
,
fakeClient
:=
newStorage
(
t
)
...
...
pkg/registry/daemon/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
etcd
package
etcd
import
(
import
(
"strings"
"testing"
"testing"
"time"
"time"
...
@@ -29,8 +28,8 @@ import (
...
@@ -29,8 +28,8 @@ import (
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
etcdgeneric
"k8s.io/kubernetes/pkg/registry/generic/etcd"
etcdgeneric
"k8s.io/kubernetes/pkg/registry/generic/etcd"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
etcdstorage
"k8s.io/kubernetes/pkg/storage/etcd"
etcdstorage
"k8s.io/kubernetes/pkg/storage/etcd"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools/etcdtest"
"k8s.io/kubernetes/pkg/tools/etcdtest"
...
@@ -41,18 +40,9 @@ const (
...
@@ -41,18 +40,9 @@ const (
FAIL
FAIL
)
)
func
newEtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
storage
.
Interface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
helper
:=
etcdstorage
.
NewEtcdStorage
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
}
// newStorage creates a REST storage backed by etcd helpers
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
fakeEtcdClient
,
h
:=
newEtcdStorage
(
t
)
etcdStorage
,
fakeClient
:=
registrytest
.
NewEtcdStorage
(
t
)
storage
:=
NewREST
(
h
)
return
NewREST
(
etcdStorage
),
fakeClient
return
storage
,
fakeEtcdClient
}
}
// createController is a helper function that returns a controller with the updated resource version.
// createController is a helper function that returns a controller with the updated resource version.
...
@@ -95,6 +85,33 @@ var validController = api.Daemon{
...
@@ -95,6 +85,33 @@ var validController = api.Daemon{
Spec
:
validControllerSpec
,
Spec
:
validControllerSpec
,
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
storage
,
fakeClient
:=
newStorage
(
t
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeClient
.
SetError
)
test
.
TestCreate
(
// valid
&
api
.
Daemon
{
Spec
:
api
.
DaemonSpec
{
Selector
:
map
[
string
]
string
{
"a"
:
"b"
},
Template
:
&
validPodTemplate
.
Template
,
},
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
&
api
.
Daemon
{
Spec
:
api
.
DaemonSpec
{
Selector
:
map
[
string
]
string
{},
Template
:
&
validPodTemplate
.
Template
,
},
},
)
}
// makeControllerKey constructs etcd paths to controller items enforcing namespace rules.
// makeControllerKey constructs etcd paths to controller items enforcing namespace rules.
func
makeControllerKey
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
{
func
makeControllerKey
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
{
return
etcdgeneric
.
NamespaceKeyFunc
(
ctx
,
daemonPrefix
,
id
)
return
etcdgeneric
.
NamespaceKeyFunc
(
ctx
,
daemonPrefix
,
id
)
...
@@ -106,103 +123,6 @@ func makeControllerListKey(ctx api.Context) string {
...
@@ -106,103 +123,6 @@ func makeControllerListKey(ctx api.Context) string {
return
etcdgeneric
.
NamespaceKeyRootFunc
(
ctx
,
daemonPrefix
)
return
etcdgeneric
.
NamespaceKeyRootFunc
(
ctx
,
daemonPrefix
)
}
}
func
TestEtcdCreateController
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
storage
,
fakeClient
:=
newStorage
(
t
)
_
,
err
:=
storage
.
Create
(
ctx
,
&
validController
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
key
,
_
:=
makeControllerKey
(
ctx
,
validController
.
Name
)
key
=
etcdtest
.
AddPrefix
(
key
)
resp
,
err
:=
fakeClient
.
Get
(
key
,
false
,
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
var
ctrl
api
.
Daemon
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
ctrl
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
ctrl
.
Name
!=
"foo"
{
t
.
Errorf
(
"Unexpected controller: %#v %s"
,
ctrl
,
resp
.
Node
.
Value
)
}
}
func
TestEtcdCreateControllerAlreadyExisting
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
storage
,
fakeClient
:=
newStorage
(
t
)
key
,
_
:=
makeControllerKey
(
ctx
,
validController
.
Name
)
key
=
etcdtest
.
AddPrefix
(
key
)
fakeClient
.
Set
(
key
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
validController
),
0
)
_
,
err
:=
storage
.
Create
(
ctx
,
&
validController
)
if
!
errors
.
IsAlreadyExists
(
err
)
{
t
.
Errorf
(
"expected already exists err, got %#v"
,
err
)
}
}
func
TestEtcdCreateControllerValidates
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
storage
,
_
:=
newStorage
(
t
)
emptyName
:=
validController
emptyName
.
Name
=
""
failureCases
:=
[]
api
.
Daemon
{
emptyName
}
for
_
,
failureCase
:=
range
failureCases
{
c
,
err
:=
storage
.
Create
(
ctx
,
&
failureCase
)
if
c
!=
nil
{
t
.
Errorf
(
"Expected nil channel"
)
}
if
!
errors
.
IsInvalid
(
err
)
{
t
.
Errorf
(
"Expected to get an invalid resource error, got %v"
,
err
)
}
}
}
func
TestCreateControllerWithGeneratedName
(
t
*
testing
.
T
)
{
storage
,
_
:=
newStorage
(
t
)
controller
:=
&
api
.
Daemon
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
GenerateName
:
"daemon-"
,
},
Spec
:
api
.
DaemonSpec
{
Selector
:
map
[
string
]
string
{
"a"
:
"b"
},
Template
:
&
validPodTemplate
.
Template
,
},
}
ctx
:=
api
.
NewDefaultContext
()
_
,
err
:=
storage
.
Create
(
ctx
,
controller
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
controller
.
Name
==
"daemon-"
||
!
strings
.
HasPrefix
(
controller
.
Name
,
"daemon-"
)
{
t
.
Errorf
(
"unexpected name: %#v"
,
controller
)
}
}
func
TestCreateControllerWithConflictingNamespace
(
t
*
testing
.
T
)
{
storage
,
_
:=
newStorage
(
t
)
controller
:=
&
api
.
Daemon
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
,
Namespace
:
"not-default"
},
}
ctx
:=
api
.
NewDefaultContext
()
channel
,
err
:=
storage
.
Create
(
ctx
,
controller
)
if
channel
!=
nil
{
t
.
Error
(
"Expected a nil channel, but we got a value"
)
}
errSubString
:=
"namespace"
if
err
==
nil
{
t
.
Errorf
(
"Expected an error, but we didn't get one"
)
}
else
if
!
errors
.
IsBadRequest
(
err
)
||
strings
.
Index
(
err
.
Error
(),
errSubString
)
==
-
1
{
t
.
Errorf
(
"Expected a Bad Request error with the sub string '%s', got %v"
,
errSubString
,
err
)
}
}
func
TestEtcdGetController
(
t
*
testing
.
T
)
{
func
TestEtcdGetController
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
storage
,
fakeClient
:=
newStorage
(
t
)
storage
,
fakeClient
:=
newStorage
(
t
)
...
@@ -653,27 +573,6 @@ func TestEtcdWatchControllersNotMatch(t *testing.T) {
...
@@ -653,27 +573,6 @@ func TestEtcdWatchControllersNotMatch(t *testing.T) {
}
}
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
storage
,
fakeClient
:=
newStorage
(
t
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeClient
.
SetError
)
test
.
TestCreate
(
// valid
&
api
.
Daemon
{
Spec
:
api
.
DaemonSpec
{
Selector
:
map
[
string
]
string
{
"a"
:
"b"
},
Template
:
&
validPodTemplate
.
Template
,
},
},
// invalid
&
api
.
Daemon
{
Spec
:
api
.
DaemonSpec
{
Selector
:
map
[
string
]
string
{},
Template
:
&
validPodTemplate
.
Template
,
},
},
)
}
func
TestDelete
(
t
*
testing
.
T
)
{
func
TestDelete
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
storage
,
fakeClient
:=
newStorage
(
t
)
storage
,
fakeClient
:=
newStorage
(
t
)
...
...
pkg/registry/endpoint/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -67,6 +67,12 @@ func TestCreate(t *testing.T) {
...
@@ -67,6 +67,12 @@ func TestCreate(t *testing.T) {
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
endpoints
,
endpoints
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
// invalid
&
api
.
Endpoints
{
&
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"_-a123-a_"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"_-a123-a_"
},
...
...
pkg/registry/horizontalpodautoscaler/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -64,6 +64,12 @@ func TestCreate(t *testing.T) {
...
@@ -64,6 +64,12 @@ func TestCreate(t *testing.T) {
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
autoscaler
,
autoscaler
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
// invalid
&
expapi
.
HorizontalPodAutoscaler
{},
&
expapi
.
HorizontalPodAutoscaler
{},
)
)
...
...
pkg/registry/limitrange/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -17,21 +17,14 @@ limitations under the License.
...
@@ -17,21 +17,14 @@ limitations under the License.
package
etcd
package
etcd
import
(
import
(
"reflect"
"testing"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/rest/resttest"
etcdgeneric
"k8s.io/kubernetes/pkg/registry/generic/etcd"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools/etcdtest"
"k8s.io/kubernetes/pkg/util"
"github.com/coreos/go-etcd/etcd"
)
)
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
...
@@ -39,11 +32,11 @@ func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
...
@@ -39,11 +32,11 @@ func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
return
NewREST
(
etcdStorage
),
fakeClient
return
NewREST
(
etcdStorage
),
fakeClient
}
}
func
TestLimitRangeCreate
(
t
*
testing
.
T
)
{
func
validNewLimitRange
()
*
api
.
LimitRange
{
limitRange
:=
&
api
.
LimitRange
{
return
&
api
.
LimitRange
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Name
:
"foo"
,
Namespace
:
"default"
,
Namespace
:
api
.
NamespaceDefault
,
},
},
Spec
:
api
.
LimitRangeSpec
{
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
...
@@ -61,72 +54,25 @@ func TestLimitRangeCreate(t *testing.T) {
...
@@ -61,72 +54,25 @@ func TestLimitRangeCreate(t *testing.T) {
},
},
},
},
}
}
}
nodeWithLimitRange
:=
tools
.
EtcdResponseWithError
{
func
TestCreate
(
t
*
testing
.
T
)
{
R
:
&
etcd
.
Response
{
storage
,
fakeClient
:=
newStorage
(
t
)
Node
:
&
etcd
.
Node
{
test
:=
resttest
.
New
(
t
,
storage
,
fakeClient
.
SetError
)
.
GeneratesName
()
Value
:
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
limitRange
),
validLimitRange
:=
validNewLimitRange
()
ModifiedIndex
:
1
,
validLimitRange
.
ObjectMeta
=
api
.
ObjectMeta
{}
CreatedIndex
:
1
,
test
.
TestCreate
(
},
// valid
validLimitRange
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
},
E
:
nil
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
}
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
emptyNode
:=
tools
.
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{},
E
:
tools
.
EtcdErrorNotFound
,
}
ctx
:=
api
.
NewDefaultContext
()
key
:=
"foo"
prefix
:=
etcdtest
.
AddPrefix
(
"limitranges"
)
path
,
err
:=
etcdgeneric
.
NamespaceKeyFunc
(
ctx
,
prefix
,
key
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
table
:=
map
[
string
]
struct
{
existing
tools
.
EtcdResponseWithError
expect
tools
.
EtcdResponseWithError
toCreate
runtime
.
Object
errOK
func
(
error
)
bool
}{
"normal"
:
{
existing
:
emptyNode
,
expect
:
nodeWithLimitRange
,
toCreate
:
limitRange
,
errOK
:
func
(
err
error
)
bool
{
return
err
==
nil
},
},
},
"preExisting"
:
{
// invalid
existing
:
nodeWithLimitRange
,
&
api
.
LimitRange
{
expect
:
nodeWithLimitRange
,
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"_-a123-a_"
},
toCreate
:
limitRange
,
errOK
:
errors
.
IsAlreadyExists
,
},
},
}
)
for
name
,
item
:=
range
table
{
storage
,
fakeClient
:=
newStorage
(
t
)
fakeClient
.
Data
[
path
]
=
item
.
existing
_
,
err
:=
storage
.
Create
(
ctx
,
item
.
toCreate
)
if
!
item
.
errOK
(
err
)
{
t
.
Errorf
(
"%v: unexpected error: %v"
,
name
,
err
)
}
received
:=
fakeClient
.
Data
[
path
]
var
limitRange
api
.
LimitRange
if
err
:=
testapi
.
Codec
()
.
DecodeInto
([]
byte
(
received
.
R
.
Node
.
Value
),
&
limitRange
);
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
// Unset CreationTimestamp and UID which are set automatically by infrastructure.
limitRange
.
ObjectMeta
.
CreationTimestamp
=
util
.
Time
{}
limitRange
.
ObjectMeta
.
UID
=
""
received
.
R
.
Node
.
Value
=
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
&
limitRange
)
if
e
,
a
:=
item
.
expect
,
received
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"%v:
\n
%s"
,
name
,
util
.
ObjectDiff
(
e
,
a
))
}
}
}
}
pkg/registry/minion/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -82,6 +82,12 @@ func TestCreate(t *testing.T) {
...
@@ -82,6 +82,12 @@ func TestCreate(t *testing.T) {
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
node
,
node
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
// invalid
&
api
.
Node
{
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"_-a123-a_"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"_-a123-a_"
},
...
...
pkg/registry/namespace/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -68,6 +68,12 @@ func TestCreate(t *testing.T) {
...
@@ -68,6 +68,12 @@ func TestCreate(t *testing.T) {
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
namespace
,
namespace
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
// invalid
&
api
.
Namespace
{
&
api
.
Namespace
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bad value"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bad value"
},
...
...
pkg/registry/persistentvolume/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -76,6 +76,12 @@ func TestCreate(t *testing.T) {
...
@@ -76,6 +76,12 @@ func TestCreate(t *testing.T) {
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
pv
,
pv
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
// invalid
&
api
.
PersistentVolume
{
&
api
.
PersistentVolume
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"*BadName!"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"*BadName!"
},
...
...
pkg/registry/persistentvolumeclaim/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -73,6 +73,12 @@ func TestCreate(t *testing.T) {
...
@@ -73,6 +73,12 @@ func TestCreate(t *testing.T) {
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
pv
,
pv
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
// invalid
&
api
.
PersistentVolumeClaim
{
&
api
.
PersistentVolumeClaim
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"*BadName!"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"*BadName!"
},
...
...
pkg/registry/pod/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -101,6 +101,12 @@ func TestCreate(t *testing.T) {
...
@@ -101,6 +101,12 @@ func TestCreate(t *testing.T) {
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
pod
,
pod
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid (empty contains list)
// invalid (empty contains list)
&
api
.
Pod
{
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Spec
:
api
.
PodSpec
{
...
@@ -494,25 +500,6 @@ func TestEtcdCreateFailsWithoutNamespace(t *testing.T) {
...
@@ -494,25 +500,6 @@ func TestEtcdCreateFailsWithoutNamespace(t *testing.T) {
}
}
}
}
func
TestEtcdCreateAlreadyExisting
(
t
*
testing
.
T
)
{
storage
,
_
,
_
,
fakeClient
:=
newStorage
(
t
)
ctx
:=
api
.
NewDefaultContext
()
key
,
_
:=
storage
.
KeyFunc
(
ctx
,
"foo"
)
key
=
etcdtest
.
AddPrefix
(
key
)
fakeClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
Node
:
&
etcd
.
Node
{
Value
:
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}),
},
},
E
:
nil
,
}
_
,
err
:=
storage
.
Create
(
ctx
,
validNewPod
())
if
!
errors
.
IsAlreadyExists
(
err
)
{
t
.
Errorf
(
"Unexpected error returned: %#v"
,
err
)
}
}
func
TestEtcdCreateWithContainersNotFound
(
t
*
testing
.
T
)
{
func
TestEtcdCreateWithContainersNotFound
(
t
*
testing
.
T
)
{
storage
,
bindingStorage
,
_
,
fakeClient
:=
newStorage
(
t
)
storage
,
bindingStorage
,
_
,
fakeClient
:=
newStorage
(
t
)
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
...
...
pkg/registry/podtemplate/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/rest/resttest"
"k8s.io/kubernetes/pkg/api/rest/resttest"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools/etcdtest"
"k8s.io/kubernetes/pkg/tools/etcdtest"
)
)
...
@@ -66,6 +67,12 @@ func TestCreate(t *testing.T) {
...
@@ -66,6 +67,12 @@ func TestCreate(t *testing.T) {
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
pod
,
pod
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
// invalid
&
api
.
PodTemplate
{
&
api
.
PodTemplate
{
Template
:
api
.
PodTemplateSpec
{},
Template
:
api
.
PodTemplateSpec
{},
...
...
pkg/registry/registrytest/etcd.go
View file @
61de4fc3
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"github.com/coreos/go-etcd/etcd"
"github.com/coreos/go-etcd/etcd"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
"k8s.io/kubernetes/pkg/storage"
...
@@ -36,8 +37,42 @@ func NewEtcdStorage(t *testing.T) (storage.Interface, *tools.FakeEtcdClient) {
...
@@ -36,8 +37,42 @@ func NewEtcdStorage(t *testing.T) (storage.Interface, *tools.FakeEtcdClient) {
return
etcdStorage
,
fakeClient
return
etcdStorage
,
fakeClient
}
}
func
SetResourceVersion
(
fakeClient
*
tools
.
FakeEtcdClient
,
resourceVersion
uint64
)
{
type
keyFunc
func
(
api
.
Context
,
string
)
(
string
,
error
)
fakeClient
.
ChangeIndex
=
resourceVersion
type
newFunc
func
()
runtime
.
Object
func
GetObject
(
fakeClient
*
tools
.
FakeEtcdClient
,
keyFn
keyFunc
,
newFn
newFunc
,
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
meta
,
err
:=
api
.
ObjectMetaFor
(
obj
)
if
err
!=
nil
{
return
nil
,
err
}
key
,
err
:=
keyFn
(
ctx
,
meta
.
Name
)
if
err
!=
nil
{
return
nil
,
err
}
key
=
etcdtest
.
AddPrefix
(
key
)
resp
,
err
:=
fakeClient
.
Get
(
key
,
false
,
false
)
if
err
!=
nil
{
return
nil
,
err
}
result
:=
newFn
()
if
err
:=
testapi
.
Codec
()
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
result
);
err
!=
nil
{
return
nil
,
err
}
return
result
,
nil
}
func
SetObject
(
fakeClient
*
tools
.
FakeEtcdClient
,
keyFn
keyFunc
,
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
meta
,
err
:=
api
.
ObjectMetaFor
(
obj
)
if
err
!=
nil
{
return
err
}
key
,
err
:=
keyFn
(
ctx
,
meta
.
Name
)
if
err
!=
nil
{
return
err
}
key
=
etcdtest
.
AddPrefix
(
key
)
_
,
err
=
fakeClient
.
Set
(
key
,
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
obj
),
0
)
return
err
}
}
func
SetObjectsForKey
(
fakeClient
*
tools
.
FakeEtcdClient
,
key
string
,
objects
[]
runtime
.
Object
)
[]
runtime
.
Object
{
func
SetObjectsForKey
(
fakeClient
*
tools
.
FakeEtcdClient
,
key
string
,
objects
[]
runtime
.
Object
)
[]
runtime
.
Object
{
...
@@ -66,3 +101,7 @@ func SetObjectsForKey(fakeClient *tools.FakeEtcdClient, key string, objects []ru
...
@@ -66,3 +101,7 @@ func SetObjectsForKey(fakeClient *tools.FakeEtcdClient, key string, objects []ru
}
}
return
result
return
result
}
}
func
SetResourceVersion
(
fakeClient
*
tools
.
FakeEtcdClient
,
resourceVersion
uint64
)
{
fakeClient
.
ChangeIndex
=
resourceVersion
}
pkg/registry/resourcequota/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -18,12 +18,10 @@ package etcd
...
@@ -18,12 +18,10 @@ package etcd
import
(
import
(
"fmt"
"fmt"
"strings"
"testing"
"testing"
"time"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/rest/resttest"
"k8s.io/kubernetes/pkg/api/rest/resttest"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
...
@@ -86,6 +84,12 @@ func TestCreate(t *testing.T) {
...
@@ -86,6 +84,12 @@ func TestCreate(t *testing.T) {
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
resourcequota
,
resourcequota
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
// invalid
&
api
.
ResourceQuota
{
&
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"_-a123-a_"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"_-a123-a_"
},
...
@@ -202,36 +206,6 @@ func TestEtcdList(t *testing.T) {
...
@@ -202,36 +206,6 @@ func TestEtcdList(t *testing.T) {
})
})
}
}
func
TestEtcdCreateFailsWithoutNamespace
(
t
*
testing
.
T
)
{
storage
,
_
,
_
:=
newStorage
(
t
)
resourcequota
:=
validNewResourceQuota
()
resourcequota
.
Namespace
=
""
_
,
err
:=
storage
.
Create
(
api
.
NewContext
(),
resourcequota
)
// Accept "namespace" or "Namespace".
if
err
==
nil
||
!
strings
.
Contains
(
err
.
Error
(),
"amespace"
)
{
t
.
Fatalf
(
"expected error that namespace was missing from context, got: %v"
,
err
)
}
}
func
TestEtcdCreateAlreadyExisting
(
t
*
testing
.
T
)
{
storage
,
_
,
fakeClient
:=
newStorage
(
t
)
ctx
:=
api
.
NewDefaultContext
()
key
,
_
:=
storage
.
KeyFunc
(
ctx
,
"foo"
)
key
=
etcdtest
.
AddPrefix
(
key
)
fakeClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
Node
:
&
etcd
.
Node
{
Value
:
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
&
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}),
},
},
E
:
nil
,
}
_
,
err
:=
storage
.
Create
(
ctx
,
validNewResourceQuota
())
if
!
errors
.
IsAlreadyExists
(
err
)
{
t
.
Errorf
(
"Unexpected error returned: %#v"
,
err
)
}
}
func
TestEtcdUpdateStatus
(
t
*
testing
.
T
)
{
func
TestEtcdUpdateStatus
(
t
*
testing
.
T
)
{
storage
,
status
,
fakeClient
:=
newStorage
(
t
)
storage
,
status
,
fakeClient
:=
newStorage
(
t
)
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
...
...
pkg/registry/secret/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/rest/resttest"
"k8s.io/kubernetes/pkg/api/rest/resttest"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools/etcdtest"
"k8s.io/kubernetes/pkg/tools/etcdtest"
)
)
...
@@ -51,6 +52,12 @@ func TestCreate(t *testing.T) {
...
@@ -51,6 +52,12 @@ func TestCreate(t *testing.T) {
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
secret
,
secret
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
// invalid
&
api
.
Secret
{},
&
api
.
Secret
{},
&
api
.
Secret
{
&
api
.
Secret
{
...
...
pkg/registry/service/etcd/etcd_test.go
0 → 100644
View file @
61de4fc3
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
etcd
import
(
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/rest/resttest"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/util"
)
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
etcdStorage
,
fakeClient
:=
registrytest
.
NewEtcdStorage
(
t
)
return
NewREST
(
etcdStorage
),
fakeClient
}
func
validService
()
*
api
.
Service
{
return
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
api
.
NamespaceDefault
,
},
Spec
:
api
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
ClusterIP
:
"None"
,
SessionAffinity
:
"None"
,
Type
:
api
.
ServiceTypeClusterIP
,
Ports
:
[]
api
.
ServicePort
{{
Port
:
6502
,
Protocol
:
api
.
ProtocolTCP
,
TargetPort
:
util
.
NewIntOrStringFromInt
(
6502
),
}},
},
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
storage
,
fakeClient
:=
newStorage
(
t
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeClient
.
SetError
)
validService
:=
validService
()
validService
.
ObjectMeta
=
api
.
ObjectMeta
{}
test
.
TestCreate
(
// valid
validService
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{},
},
// invalid
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
ClusterIP
:
"invalid"
,
SessionAffinity
:
"None"
,
Type
:
api
.
ServiceTypeClusterIP
,
Ports
:
[]
api
.
ServicePort
{{
Port
:
6502
,
Protocol
:
api
.
ProtocolTCP
,
TargetPort
:
util
.
NewIntOrStringFromInt
(
6502
),
}},
},
},
)
}
pkg/registry/service/rest_test.go
View file @
61de4fc3
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/api/rest/resttest"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/registry/registrytest"
...
@@ -33,6 +32,10 @@ import (
...
@@ -33,6 +32,10 @@ import (
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util"
)
)
// TODO(wojtek-t): Cleanup this file.
// It is now testing mostly the same things as other resources but
// in a completely different way. We should unify it.
func
NewTestREST
(
t
*
testing
.
T
,
endpoints
*
api
.
EndpointsList
)
(
*
REST
,
*
registrytest
.
ServiceRegistry
)
{
func
NewTestREST
(
t
*
testing
.
T
,
endpoints
*
api
.
EndpointsList
)
(
*
REST
,
*
registrytest
.
ServiceRegistry
)
{
registry
:=
registrytest
.
NewServiceRegistry
()
registry
:=
registrytest
.
NewServiceRegistry
()
endpointRegistry
:=
&
registrytest
.
EndpointRegistry
{
endpointRegistry
:=
&
registrytest
.
EndpointRegistry
{
...
@@ -741,25 +744,6 @@ func TestServiceRegistryIPLoadBalancer(t *testing.T) {
...
@@ -741,25 +744,6 @@ func TestServiceRegistryIPLoadBalancer(t *testing.T) {
}
}
}
}
// TODO: remove, covered by TestCreate
func
TestCreateServiceWithConflictingNamespace
(
t
*
testing
.
T
)
{
storage
:=
REST
{}
service
:=
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
,
Namespace
:
"not-default"
},
}
ctx
:=
api
.
NewDefaultContext
()
obj
,
err
:=
storage
.
Create
(
ctx
,
service
)
if
obj
!=
nil
{
t
.
Error
(
"Expected a nil object, but we got a value"
)
}
if
err
==
nil
{
t
.
Errorf
(
"Expected an error, but we didn't get one"
)
}
else
if
strings
.
Contains
(
err
.
Error
(),
"Service.Namespace does not match the provided context"
)
{
t
.
Errorf
(
"Expected 'Service.Namespace does not match the provided context' error, got '%s'"
,
err
.
Error
())
}
}
func
TestUpdateServiceWithConflictingNamespace
(
t
*
testing
.
T
)
{
func
TestUpdateServiceWithConflictingNamespace
(
t
*
testing
.
T
)
{
storage
:=
REST
{}
storage
:=
REST
{}
service
:=
&
api
.
Service
{
service
:=
&
api
.
Service
{
...
@@ -777,43 +761,3 @@ func TestUpdateServiceWithConflictingNamespace(t *testing.T) {
...
@@ -777,43 +761,3 @@ func TestUpdateServiceWithConflictingNamespace(t *testing.T) {
t
.
Errorf
(
"Expected 'Service.Namespace does not match the provided context' error, got '%s'"
,
err
.
Error
())
t
.
Errorf
(
"Expected 'Service.Namespace does not match the provided context' error, got '%s'"
,
err
.
Error
())
}
}
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
rest
,
registry
:=
NewTestREST
(
t
,
nil
)
test
:=
resttest
.
New
(
t
,
rest
,
registry
.
SetError
)
test
.
TestCreate
(
// valid
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
ClusterIP
:
"None"
,
SessionAffinity
:
"None"
,
Type
:
api
.
ServiceTypeClusterIP
,
Ports
:
[]
api
.
ServicePort
{{
Port
:
6502
,
Protocol
:
api
.
ProtocolTCP
,
TargetPort
:
util
.
NewIntOrStringFromInt
(
6502
),
}},
},
},
// invalid
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{},
},
// invalid
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
ClusterIP
:
"invalid"
,
SessionAffinity
:
"None"
,
Type
:
api
.
ServiceTypeClusterIP
,
Ports
:
[]
api
.
ServicePort
{{
Port
:
6502
,
Protocol
:
api
.
ProtocolTCP
,
TargetPort
:
util
.
NewIntOrStringFromInt
(
6502
),
}},
},
},
)
}
pkg/registry/serviceaccount/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/rest/resttest"
"k8s.io/kubernetes/pkg/api/rest/resttest"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools/etcdtest"
"k8s.io/kubernetes/pkg/tools/etcdtest"
)
)
...
@@ -49,6 +50,12 @@ func TestCreate(t *testing.T) {
...
@@ -49,6 +50,12 @@ func TestCreate(t *testing.T) {
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
serviceAccount
,
serviceAccount
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
// invalid
&
api
.
ServiceAccount
{},
&
api
.
ServiceAccount
{},
&
api
.
ServiceAccount
{
&
api
.
ServiceAccount
{
...
...
pkg/registry/thirdpartyresource/etcd/etcd_test.go
View file @
61de4fc3
...
@@ -26,29 +26,22 @@ import (
...
@@ -26,29 +26,22 @@ import (
"k8s.io/kubernetes/pkg/expapi/v1"
"k8s.io/kubernetes/pkg/expapi/v1"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
etcdstorage
"k8s.io/kubernetes/pkg/storage/etcd"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools/etcdtest"
"k8s.io/kubernetes/pkg/tools/etcdtest"
"github.com/coreos/go-etcd/etcd"
"github.com/coreos/go-etcd/etcd"
)
)
var
scheme
*
runtime
.
Scheme
var
codec
runtime
.
Codec
func
init
()
{
func
init
()
{
// Ensure that expapi/v1 packege is used, so that it will get initialized and register HorizontalPodAutoscaler object.
// Ensure that expapi/v1 packege is used, so that it will get initialized and register HorizontalPodAutoscaler object.
_
=
v1
.
ThirdPartyResource
{}
_
=
v1
.
ThirdPartyResource
{}
}
}
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
,
storage
.
Interface
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
etcdStorage
,
fakeClient
:=
registrytest
.
NewEtcdStorage
(
t
)
fakeEtcdClient
.
TestIndex
=
true
return
NewREST
(
etcdStorage
),
fakeClient
etcdStorage
:=
etcdstorage
.
NewEtcdStorage
(
fakeEtcdClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
storage
:=
NewREST
(
etcdStorage
)
return
storage
,
fakeEtcdClient
,
etcdStorage
}
}
func
validNewThirdPartyResource
(
name
string
)
*
expapi
.
ThirdPartyResource
{
func
validNewThirdPartyResource
(
name
string
)
*
expapi
.
ThirdPartyResource
{
...
@@ -66,28 +59,34 @@ func validNewThirdPartyResource(name string) *expapi.ThirdPartyResource {
...
@@ -66,28 +59,34 @@ func validNewThirdPartyResource(name string) *expapi.ThirdPartyResource {
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
func
TestCreate
(
t
*
testing
.
T
)
{
storage
,
fake
EtcdClient
,
_
:=
newStorage
(
t
)
storage
,
fake
Client
:=
newStorage
(
t
)
test
:=
resttest
.
New
(
t
,
storage
,
fake
Etcd
Client
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeClient
.
SetError
)
rsrc
:=
validNewThirdPartyResource
(
"foo"
)
rsrc
:=
validNewThirdPartyResource
(
"foo"
)
rsrc
.
ObjectMeta
=
api
.
ObjectMeta
{}
rsrc
.
ObjectMeta
=
api
.
ObjectMeta
{}
test
.
TestCreate
(
test
.
TestCreate
(
// valid
// valid
rsrc
,
rsrc
,
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
error
{
return
registrytest
.
SetObject
(
fakeClient
,
storage
.
KeyFunc
,
ctx
,
obj
)
},
func
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
registrytest
.
GetObject
(
fakeClient
,
storage
.
KeyFunc
,
storage
.
NewFunc
,
ctx
,
obj
)
},
// invalid
// invalid
&
expapi
.
ThirdPartyResource
{},
&
expapi
.
ThirdPartyResource
{},
)
)
}
}
func
TestUpdate
(
t
*
testing
.
T
)
{
func
TestUpdate
(
t
*
testing
.
T
)
{
storage
,
fake
EtcdClient
,
_
:=
newStorage
(
t
)
storage
,
fake
Client
:=
newStorage
(
t
)
test
:=
resttest
.
New
(
t
,
storage
,
fake
Etcd
Client
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeClient
.
SetError
)
key
,
err
:=
storage
.
KeyFunc
(
test
.
TestContext
(),
"foo"
)
key
,
err
:=
storage
.
KeyFunc
(
test
.
TestContext
(),
"foo"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
fake
Etcd
Client
.
ExpectNotFoundGet
(
key
)
fakeClient
.
ExpectNotFoundGet
(
key
)
fake
Etcd
Client
.
ChangeIndex
=
2
fakeClient
.
ChangeIndex
=
2
rsrc
:=
validNewThirdPartyResource
(
"foo"
)
rsrc
:=
validNewThirdPartyResource
(
"foo"
)
existing
:=
validNewThirdPartyResource
(
"exists"
)
existing
:=
validNewThirdPartyResource
(
"exists"
)
existing
.
Namespace
=
test
.
TestNamespace
()
existing
.
Namespace
=
test
.
TestNamespace
()
...
@@ -106,13 +105,13 @@ func TestUpdate(t *testing.T) {
...
@@ -106,13 +105,13 @@ func TestUpdate(t *testing.T) {
func
TestDelete
(
t
*
testing
.
T
)
{
func
TestDelete
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
storage
,
fake
EtcdClient
,
_
:=
newStorage
(
t
)
storage
,
fake
Client
:=
newStorage
(
t
)
test
:=
resttest
.
New
(
t
,
storage
,
fake
Etcd
Client
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeClient
.
SetError
)
rsrc
:=
validNewThirdPartyResource
(
"foo2"
)
rsrc
:=
validNewThirdPartyResource
(
"foo2"
)
key
,
_
:=
storage
.
KeyFunc
(
ctx
,
"foo2"
)
key
,
_
:=
storage
.
KeyFunc
(
ctx
,
"foo2"
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
createFn
:=
func
()
runtime
.
Object
{
createFn
:=
func
()
runtime
.
Object
{
fake
Etcd
Client
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
fakeClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
Node
:
&
etcd
.
Node
{
Node
:
&
etcd
.
Node
{
Value
:
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
rsrc
),
Value
:
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
rsrc
),
...
@@ -123,24 +122,24 @@ func TestDelete(t *testing.T) {
...
@@ -123,24 +122,24 @@ func TestDelete(t *testing.T) {
return
rsrc
return
rsrc
}
}
gracefulSetFn
:=
func
()
bool
{
gracefulSetFn
:=
func
()
bool
{
if
fake
Etcd
Client
.
Data
[
key
]
.
R
.
Node
==
nil
{
if
fakeClient
.
Data
[
key
]
.
R
.
Node
==
nil
{
return
false
return
false
}
}
return
fake
Etcd
Client
.
Data
[
key
]
.
R
.
Node
.
TTL
==
30
return
fakeClient
.
Data
[
key
]
.
R
.
Node
.
TTL
==
30
}
}
test
.
TestDeleteNoGraceful
(
createFn
,
gracefulSetFn
)
test
.
TestDeleteNoGraceful
(
createFn
,
gracefulSetFn
)
}
}
func
TestGet
(
t
*
testing
.
T
)
{
func
TestGet
(
t
*
testing
.
T
)
{
storage
,
fake
EtcdClient
,
_
:=
newStorage
(
t
)
storage
,
fake
Client
:=
newStorage
(
t
)
test
:=
resttest
.
New
(
t
,
storage
,
fake
Etcd
Client
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeClient
.
SetError
)
rsrc
:=
validNewThirdPartyResource
(
"foo"
)
rsrc
:=
validNewThirdPartyResource
(
"foo"
)
test
.
TestGet
(
rsrc
)
test
.
TestGet
(
rsrc
)
}
}
func
TestEmptyList
(
t
*
testing
.
T
)
{
func
TestEmptyList
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
registry
,
fakeClient
,
_
:=
newStorage
(
t
)
registry
,
fakeClient
:=
newStorage
(
t
)
fakeClient
.
ChangeIndex
=
1
fakeClient
.
ChangeIndex
=
1
key
:=
registry
.
KeyRootFunc
(
ctx
)
key
:=
registry
.
KeyRootFunc
(
ctx
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
...
@@ -162,7 +161,7 @@ func TestEmptyList(t *testing.T) {
...
@@ -162,7 +161,7 @@ func TestEmptyList(t *testing.T) {
func
TestList
(
t
*
testing
.
T
)
{
func
TestList
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
registry
,
fakeClient
,
_
:=
newStorage
(
t
)
registry
,
fakeClient
:=
newStorage
(
t
)
fakeClient
.
ChangeIndex
=
1
fakeClient
.
ChangeIndex
=
1
key
:=
registry
.
KeyRootFunc
(
ctx
)
key
:=
registry
.
KeyRootFunc
(
ctx
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
...
...
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