mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Add registrytest support for etcd tests.
This commit is contained in:
parent
3dd3aa2730
commit
a4baf4c211
@ -79,18 +79,12 @@ var validController = validNewController()
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
controller := validNewController()
|
controller := validNewController()
|
||||||
controller.ObjectMeta = api.ObjectMeta{}
|
controller.ObjectMeta = api.ObjectMeta{}
|
||||||
test.TestCreate(
|
test.TestCreate(
|
||||||
// valid
|
// valid
|
||||||
controller,
|
controller,
|
||||||
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 selector)
|
// invalid (invalid selector)
|
||||||
&api.ReplicationController{
|
&api.ReplicationController{
|
||||||
Spec: api.ReplicationControllerSpec{
|
Spec: api.ReplicationControllerSpec{
|
||||||
@ -104,20 +98,11 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewController(),
|
validNewController(),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
// valid updateFunc
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*api.ReplicationController)
|
object := obj.(*api.ReplicationController)
|
||||||
object.Spec.Replicas = object.Spec.Replicas + 1
|
object.Spec.Replicas = object.Spec.Replicas + 1
|
||||||
@ -191,40 +176,23 @@ func TestGenerationNumber(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetController(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestGet(validNewController())
|
test.TestGet(validNewController())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListControllers(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
test.TestList(validNewController())
|
||||||
test.TestList(
|
|
||||||
validNewController(),
|
|
||||||
func(objects []runtime.Object) []runtime.Object {
|
|
||||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchControllers(t *testing.T) {
|
func TestWatch(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestWatch(
|
test.TestWatch(
|
||||||
validController,
|
validController,
|
||||||
func() {
|
|
||||||
fakeClient.WaitForWatchCompletion()
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
fakeClient.WatchInjectError <- err
|
|
||||||
},
|
|
||||||
func(obj runtime.Object, action string) error {
|
|
||||||
return registrytest.EmitObject(fakeClient, obj, action)
|
|
||||||
},
|
|
||||||
// matching labels
|
// matching labels
|
||||||
[]labels.Set{
|
[]labels.Set{
|
||||||
{"a": "b"},
|
{"a": "b"},
|
||||||
@ -248,7 +216,6 @@ func TestWatchControllers(t *testing.T) {
|
|||||||
{"status.replicas": "10", "metadata.name": "foo"},
|
{"status.replicas": "10", "metadata.name": "foo"},
|
||||||
{"status.replicas": "0", "metadata.name": "bar"},
|
{"status.replicas": "0", "metadata.name": "bar"},
|
||||||
},
|
},
|
||||||
registrytest.WatchActions,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,17 +37,6 @@ func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
|||||||
return NewREST(etcdStorage), fakeClient
|
return NewREST(etcdStorage), fakeClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// createController is a helper function that returns a controller with the updated resource version.
|
|
||||||
func createController(storage *REST, dc expapi.Daemon, t *testing.T) (expapi.Daemon, error) {
|
|
||||||
ctx := api.WithNamespace(api.NewContext(), dc.Namespace)
|
|
||||||
obj, err := storage.Create(ctx, &dc)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Failed to create controller, %v", err)
|
|
||||||
}
|
|
||||||
newDc := obj.(*expapi.Daemon)
|
|
||||||
return *newDc, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func validNewDaemon() *expapi.Daemon {
|
func validNewDaemon() *expapi.Daemon {
|
||||||
return &expapi.Daemon{
|
return &expapi.Daemon{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
@ -80,18 +69,12 @@ var validDaemon = validNewDaemon()
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
daemon := validNewDaemon()
|
daemon := validNewDaemon()
|
||||||
daemon.ObjectMeta = api.ObjectMeta{}
|
daemon.ObjectMeta = api.ObjectMeta{}
|
||||||
test.TestCreate(
|
test.TestCreate(
|
||||||
// valid
|
// valid
|
||||||
daemon,
|
daemon,
|
||||||
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 selector)
|
// invalid (invalid selector)
|
||||||
&expapi.Daemon{
|
&expapi.Daemon{
|
||||||
Spec: expapi.DaemonSpec{
|
Spec: expapi.DaemonSpec{
|
||||||
@ -104,19 +87,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewDaemon(),
|
validNewDaemon(),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*expapi.Daemon)
|
object := obj.(*expapi.Daemon)
|
||||||
@ -147,40 +121,23 @@ func TestUpdate(t *testing.T) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetController(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestGet(validNewDaemon())
|
test.TestGet(validNewDaemon())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListControllers(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
test.TestList(validNewDaemon())
|
||||||
test.TestList(
|
|
||||||
validNewDaemon(),
|
|
||||||
func(objects []runtime.Object) []runtime.Object {
|
|
||||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchControllers(t *testing.T) {
|
func TestWatch(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestWatch(
|
test.TestWatch(
|
||||||
validDaemon,
|
validDaemon,
|
||||||
func() {
|
|
||||||
fakeClient.WaitForWatchCompletion()
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
fakeClient.WatchInjectError <- err
|
|
||||||
},
|
|
||||||
func(obj runtime.Object, action string) error {
|
|
||||||
return registrytest.EmitObject(fakeClient, obj, action)
|
|
||||||
},
|
|
||||||
// matching labels
|
// matching labels
|
||||||
[]labels.Set{
|
[]labels.Set{
|
||||||
{"a": "b"},
|
{"a": "b"},
|
||||||
@ -199,11 +156,10 @@ func TestWatchControllers(t *testing.T) {
|
|||||||
{"metadata.name": "bar"},
|
{"metadata.name": "bar"},
|
||||||
{"name": "foo"},
|
{"name": "foo"},
|
||||||
},
|
},
|
||||||
registrytest.WatchActions,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdDeleteController(t *testing.T) {
|
func TestEtcdDeleteDaemon(t *testing.T) {
|
||||||
ctx := api.NewDefaultContext()
|
ctx := api.NewDefaultContext()
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
key, err := storage.KeyFunc(ctx, validDaemon.Name)
|
key, err := storage.KeyFunc(ctx, validDaemon.Name)
|
||||||
@ -248,7 +204,7 @@ func TestDelete(t *testing.T) {
|
|||||||
return dc
|
return dc
|
||||||
}
|
}
|
||||||
gracefulSetFn := func() bool {
|
gracefulSetFn := func() bool {
|
||||||
// If the controller is still around after trying to delete either the delete
|
// If the daemon is still around after trying to delete either the delete
|
||||||
// failed, or we're deleting it gracefully.
|
// failed, or we're deleting it gracefully.
|
||||||
if fakeClient.Data[key].R.Node != nil {
|
if fakeClient.Data[key].R.Node != nil {
|
||||||
return true
|
return true
|
||||||
|
@ -18,7 +18,6 @@ package etcd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/coreos/go-etcd/etcd"
|
"github.com/coreos/go-etcd/etcd"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
@ -27,19 +26,12 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/expapi"
|
"k8s.io/kubernetes/pkg/expapi"
|
||||||
"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"
|
|
||||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
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"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
PASS = iota
|
|
||||||
FAIL
|
|
||||||
)
|
|
||||||
|
|
||||||
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
||||||
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
|
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
|
||||||
return NewREST(etcdStorage), fakeClient
|
return NewREST(etcdStorage), fakeClient
|
||||||
@ -77,18 +69,12 @@ var validDeployment = *validNewDeployment()
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
deployment := validNewDeployment()
|
deployment := validNewDeployment()
|
||||||
deployment.ObjectMeta = api.ObjectMeta{}
|
deployment.ObjectMeta = api.ObjectMeta{}
|
||||||
test.TestCreate(
|
test.TestCreate(
|
||||||
// valid
|
// valid
|
||||||
deployment,
|
deployment,
|
||||||
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 selector)
|
// invalid (invalid selector)
|
||||||
&expapi.Deployment{
|
&expapi.Deployment{
|
||||||
Spec: expapi.DeploymentSpec{
|
Spec: expapi.DeploymentSpec{
|
||||||
@ -101,19 +87,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewDeployment(),
|
validNewDeployment(),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*expapi.Deployment)
|
object := obj.(*expapi.Deployment)
|
||||||
@ -144,24 +121,40 @@ func TestUpdate(t *testing.T) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestGet(validNewDeployment())
|
test.TestGet(validNewDeployment())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdList(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
test.TestList(validNewDeployment())
|
||||||
test.TestList(
|
}
|
||||||
|
|
||||||
|
func TestWatch(t *testing.T) {
|
||||||
|
storage, fakeClient := newStorage(t)
|
||||||
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
|
test.TestWatch(
|
||||||
validNewDeployment(),
|
validNewDeployment(),
|
||||||
func(objects []runtime.Object) []runtime.Object {
|
// matching labels
|
||||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
[]labels.Set{},
|
||||||
|
// not matching labels
|
||||||
|
[]labels.Set{
|
||||||
|
{"a": "c"},
|
||||||
|
{"foo": "bar"},
|
||||||
},
|
},
|
||||||
func(resourceVersion uint64) {
|
// matching fields
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
[]fields.Set{
|
||||||
})
|
{"metadata.name": "foo"},
|
||||||
|
},
|
||||||
|
// not matchin fields
|
||||||
|
[]fields.Set{
|
||||||
|
{"metadata.name": "bar"},
|
||||||
|
{"name": "foo"},
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdDelete(t *testing.T) {
|
func TestEtcdDelete(t *testing.T) {
|
||||||
@ -188,194 +181,6 @@ func TestEtcdDelete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdWatch(t *testing.T) {
|
|
||||||
ctx := api.NewDefaultContext()
|
|
||||||
storage, fakeClient := newStorage(t)
|
|
||||||
watching, err := storage.Watch(ctx,
|
|
||||||
labels.Everything(),
|
|
||||||
fields.Everything(),
|
|
||||||
"1",
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
fakeClient.WaitForWatchCompletion()
|
|
||||||
|
|
||||||
select {
|
|
||||||
case _, ok := <-watching.ResultChan():
|
|
||||||
if !ok {
|
|
||||||
t.Errorf("watching channel should be open")
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
fakeClient.WatchInjectError <- nil
|
|
||||||
if _, ok := <-watching.ResultChan(); ok {
|
|
||||||
t.Errorf("watching channel should be closed")
|
|
||||||
}
|
|
||||||
watching.Stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that we can watch for the creation of Deployment with specified labels.
|
|
||||||
func TestEtcdWatchWithLabels(t *testing.T) {
|
|
||||||
ctx := api.WithNamespace(api.NewDefaultContext(), validDeployment.Namespace)
|
|
||||||
storage, fakeClient := newStorage(t)
|
|
||||||
fakeClient.ExpectNotFoundGet(etcdgeneric.NamespaceKeyRootFunc(ctx, "/registry/pods"))
|
|
||||||
|
|
||||||
watching, err := storage.Watch(ctx,
|
|
||||||
labels.SelectorFromSet(validDeployment.Spec.Selector),
|
|
||||||
fields.Everything(),
|
|
||||||
"1",
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
fakeClient.WaitForWatchCompletion()
|
|
||||||
|
|
||||||
// The watcher above is waiting for these Labels, on receiving them it should
|
|
||||||
// apply the deploymentStatus decorator, which lists pods, causing a query against
|
|
||||||
// the /registry/pods endpoint of the etcd client.
|
|
||||||
deployment := &expapi.Deployment{
|
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
Name: "foo",
|
|
||||||
Labels: validDeployment.Spec.Selector,
|
|
||||||
Namespace: "default",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
deploymentBytes, _ := testapi.Codec().Encode(deployment)
|
|
||||||
fakeClient.WatchResponse <- &etcd.Response{
|
|
||||||
Action: "create",
|
|
||||||
Node: &etcd.Node{
|
|
||||||
Value: string(deploymentBytes),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case _, ok := <-watching.ResultChan():
|
|
||||||
if !ok {
|
|
||||||
t.Errorf("watching channel should be open")
|
|
||||||
}
|
|
||||||
case <-time.After(time.Millisecond * 100):
|
|
||||||
t.Error("unexpected timeout from result channel")
|
|
||||||
}
|
|
||||||
watching.Stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that we can watch for Deployment with specified fields.
|
|
||||||
func TestEtcdWatchWithFields(t *testing.T) {
|
|
||||||
ctx := api.WithNamespace(api.NewDefaultContext(), validDeployment.Namespace)
|
|
||||||
storage, fakeClient := newStorage(t)
|
|
||||||
fakeClient.ExpectNotFoundGet(etcdgeneric.NamespaceKeyRootFunc(ctx, "/registry/pods"))
|
|
||||||
|
|
||||||
testFieldMap := map[int][]fields.Set{
|
|
||||||
PASS: {
|
|
||||||
{"metadata.name": "foo"},
|
|
||||||
},
|
|
||||||
FAIL: {
|
|
||||||
{"metadata.name": "bar"},
|
|
||||||
{"name": "foo"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
testEtcdActions := []string{
|
|
||||||
etcdstorage.EtcdCreate,
|
|
||||||
etcdstorage.EtcdSet,
|
|
||||||
etcdstorage.EtcdCAS,
|
|
||||||
etcdstorage.EtcdDelete}
|
|
||||||
|
|
||||||
deployment := &expapi.Deployment{
|
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
Name: "foo",
|
|
||||||
Labels: validDeployment.Spec.Selector,
|
|
||||||
Namespace: "default",
|
|
||||||
},
|
|
||||||
Status: expapi.DeploymentStatus{
|
|
||||||
Replicas: 1,
|
|
||||||
UpdatedReplicas: 4,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
deploymentBytes, _ := testapi.Codec().Encode(deployment)
|
|
||||||
|
|
||||||
for expectedResult, fieldSet := range testFieldMap {
|
|
||||||
for _, field := range fieldSet {
|
|
||||||
for _, action := range testEtcdActions {
|
|
||||||
watching, err := storage.Watch(ctx,
|
|
||||||
labels.Everything(),
|
|
||||||
field.AsSelector(),
|
|
||||||
"1",
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
var prevNode *etcd.Node = nil
|
|
||||||
node := &etcd.Node{
|
|
||||||
Value: string(deploymentBytes),
|
|
||||||
}
|
|
||||||
if action == etcdstorage.EtcdDelete {
|
|
||||||
prevNode = node
|
|
||||||
}
|
|
||||||
fakeClient.WaitForWatchCompletion()
|
|
||||||
fakeClient.WatchResponse <- &etcd.Response{
|
|
||||||
Action: action,
|
|
||||||
Node: node,
|
|
||||||
PrevNode: prevNode,
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case r, ok := <-watching.ResultChan():
|
|
||||||
if expectedResult == FAIL {
|
|
||||||
t.Errorf("Unexpected result from channel %#v. Field: %v", r, field)
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
t.Errorf("watching channel should be open")
|
|
||||||
}
|
|
||||||
case <-time.After(time.Millisecond * 100):
|
|
||||||
if expectedResult == PASS {
|
|
||||||
t.Error("unexpected timeout from result channel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
watching.Stop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEtcdWatchNotMatch(t *testing.T) {
|
|
||||||
ctx := api.NewDefaultContext()
|
|
||||||
storage, fakeClient := newStorage(t)
|
|
||||||
fakeClient.ExpectNotFoundGet(etcdgeneric.NamespaceKeyRootFunc(ctx, "/registry/pods"))
|
|
||||||
|
|
||||||
watching, err := storage.Watch(ctx,
|
|
||||||
labels.SelectorFromSet(labels.Set{"name": "foo"}),
|
|
||||||
fields.Everything(),
|
|
||||||
"1",
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
fakeClient.WaitForWatchCompletion()
|
|
||||||
|
|
||||||
deployment := &expapi.Deployment{
|
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
Name: "bar",
|
|
||||||
Labels: map[string]string{
|
|
||||||
"name": "bar",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
deploymentBytes, _ := testapi.Codec().Encode(deployment)
|
|
||||||
fakeClient.WatchResponse <- &etcd.Response{
|
|
||||||
Action: "create",
|
|
||||||
Node: &etcd.Node{
|
|
||||||
Value: string(deploymentBytes),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-watching.ResultChan():
|
|
||||||
t.Error("unexpected result from result channel")
|
|
||||||
case <-time.After(time.Millisecond * 100):
|
|
||||||
// expected case
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDelete(t *testing.T) {
|
func TestDelete(t *testing.T) {
|
||||||
ctx := api.NewDefaultContext()
|
ctx := api.NewDefaultContext()
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
|
@ -61,18 +61,12 @@ func validChangedEndpoints() *api.Endpoints {
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
endpoints := validNewEndpoints()
|
endpoints := validNewEndpoints()
|
||||||
endpoints.ObjectMeta = api.ObjectMeta{}
|
endpoints.ObjectMeta = api.ObjectMeta{}
|
||||||
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_"},
|
||||||
@ -82,19 +76,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).AllowCreateOnUpdate()
|
test := registrytest.New(t, fakeClient, storage.Etcd).AllowCreateOnUpdate()
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewEndpoints(),
|
validNewEndpoints(),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*api.Endpoints)
|
object := obj.(*api.Endpoints)
|
||||||
@ -135,26 +120,16 @@ func TestDelete(t *testing.T) {
|
|||||||
test.TestDelete(createFn, gracefulSetFn)
|
test.TestDelete(createFn, gracefulSetFn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetEndpoints(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
endpoints := validNewEndpoints()
|
test.TestGet(validNewEndpoints())
|
||||||
test.TestGet(endpoints)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListEndpoints(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
endpoints := validNewEndpoints()
|
test.TestList(validNewEndpoints())
|
||||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
|
||||||
test.TestList(
|
|
||||||
endpoints,
|
|
||||||
func(objects []runtime.Object) []runtime.Object {
|
|
||||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEndpointsDecode(t *testing.T) {
|
func TestEndpointsDecode(t *testing.T) {
|
||||||
|
@ -58,18 +58,12 @@ func validNewHorizontalPodAutoscaler(name string) *expapi.HorizontalPodAutoscale
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
autoscaler := validNewHorizontalPodAutoscaler("foo")
|
autoscaler := validNewHorizontalPodAutoscaler("foo")
|
||||||
autoscaler.ObjectMeta = api.ObjectMeta{}
|
autoscaler.ObjectMeta = api.ObjectMeta{}
|
||||||
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{},
|
||||||
)
|
)
|
||||||
@ -77,19 +71,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewHorizontalPodAutoscaler("foo"),
|
validNewHorizontalPodAutoscaler("foo"),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*expapi.HorizontalPodAutoscaler)
|
object := obj.(*expapi.HorizontalPodAutoscaler)
|
||||||
@ -128,22 +113,12 @@ func TestDelete(t *testing.T) {
|
|||||||
|
|
||||||
func TestGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
autoscaler := validNewHorizontalPodAutoscaler("foo")
|
test.TestGet(validNewHorizontalPodAutoscaler("foo"))
|
||||||
test.TestGet(autoscaler)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestList(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
test.TestList(validNewHorizontalPodAutoscaler("foo"))
|
||||||
autoscaler := validNewHorizontalPodAutoscaler("foo")
|
|
||||||
test.TestList(
|
|
||||||
autoscaler,
|
|
||||||
func(objects []runtime.Object) []runtime.Object {
|
|
||||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/resource"
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
"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/runtime"
|
||||||
"k8s.io/kubernetes/pkg/tools"
|
"k8s.io/kubernetes/pkg/tools"
|
||||||
@ -58,18 +57,12 @@ func validNewLimitRange() *api.LimitRange {
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).GeneratesName()
|
test := registrytest.New(t, fakeClient, storage.Etcd).GeneratesName()
|
||||||
validLimitRange := validNewLimitRange()
|
validLimitRange := validNewLimitRange()
|
||||||
validLimitRange.ObjectMeta = api.ObjectMeta{}
|
validLimitRange.ObjectMeta = api.ObjectMeta{}
|
||||||
test.TestCreate(
|
test.TestCreate(
|
||||||
// valid
|
// valid
|
||||||
validLimitRange,
|
validLimitRange,
|
||||||
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.LimitRange{
|
&api.LimitRange{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "_-a123-a_"},
|
ObjectMeta: api.ObjectMeta{Name: "_-a123-a_"},
|
||||||
@ -79,19 +72,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).AllowCreateOnUpdate()
|
test := registrytest.New(t, fakeClient, storage.Etcd).AllowCreateOnUpdate()
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewLimitRange(),
|
validNewLimitRange(),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*api.LimitRange)
|
object := obj.(*api.LimitRange)
|
||||||
@ -112,3 +96,15 @@ func TestUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGet(t *testing.T) {
|
||||||
|
storage, fakeClient := newStorage(t)
|
||||||
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
|
test.TestGet(validNewLimitRange())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestList(t *testing.T) {
|
||||||
|
storage, fakeClient := newStorage(t)
|
||||||
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
|
test.TestList(validNewLimitRange())
|
||||||
|
}
|
||||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package limitrange
|
package limitrange
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/validation"
|
"k8s.io/kubernetes/pkg/api/validation"
|
||||||
"k8s.io/kubernetes/pkg/fields"
|
"k8s.io/kubernetes/pkg/fields"
|
||||||
@ -68,10 +70,20 @@ func (limitrangeStrategy) AllowUnconditionalUpdate() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func MatchLimitRange(label labels.Selector, field fields.Selector) generic.Matcher {
|
func LimitRangeToSelectableFields(limitRange *api.LimitRange) fields.Set {
|
||||||
return &generic.SelectionPredicate{Label: label, Field: field, GetAttrs: getAttrs}
|
return fields.Set{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAttrs(obj runtime.Object) (objLabels labels.Set, objFields fields.Set, err error) {
|
func MatchLimitRange(label labels.Selector, field fields.Selector) generic.Matcher {
|
||||||
return labels.Set{}, fields.Set{}, nil
|
return &generic.SelectionPredicate{
|
||||||
|
Label: label,
|
||||||
|
Field: field,
|
||||||
|
GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
|
||||||
|
lr, ok := obj.(*api.LimitRange)
|
||||||
|
if !ok {
|
||||||
|
return nil, nil, fmt.Errorf("given object is not a limit range.")
|
||||||
|
}
|
||||||
|
return labels.Set(lr.ObjectMeta.Labels), LimitRangeToSelectableFields(lr), nil
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func (r *StatusREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object
|
|||||||
return r.store.Update(ctx, obj)
|
return r.store.Update(ctx, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStorage returns a RESTStorage object that will work against nodes.
|
// NewREST returns a RESTStorage object that will work against nodes.
|
||||||
func NewREST(s storage.Interface, useCacher bool, connection client.ConnectionInfoGetter) (*REST, *StatusREST) {
|
func NewREST(s storage.Interface, useCacher bool, connection client.ConnectionInfoGetter) (*REST, *StatusREST) {
|
||||||
prefix := "/minions"
|
prefix := "/minions"
|
||||||
|
|
||||||
|
@ -75,18 +75,12 @@ func validChangedNode() *api.Node {
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
node := validNewNode()
|
node := validNewNode()
|
||||||
node.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
|
node.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
|
||||||
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_"},
|
||||||
@ -96,19 +90,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewNode(),
|
validNewNode(),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*api.Node)
|
object := obj.(*api.Node)
|
||||||
@ -146,42 +131,23 @@ func TestDelete(t *testing.T) {
|
|||||||
test.TestDelete(createFn, gracefulSetFn)
|
test.TestDelete(createFn, gracefulSetFn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetNode(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
node := validNewNode()
|
test.TestGet(validNewNode())
|
||||||
test.TestGet(node)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListNodes(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
test.TestList(validNewNode())
|
||||||
node := validNewNode()
|
|
||||||
test.TestList(
|
|
||||||
node,
|
|
||||||
func(objects []runtime.Object) []runtime.Object {
|
|
||||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchNodes(t *testing.T) {
|
func TestWatchNodes(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
test.TestWatch(
|
test.TestWatch(
|
||||||
validNewNode(),
|
validNewNode(),
|
||||||
func() {
|
|
||||||
fakeClient.WaitForWatchCompletion()
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
fakeClient.WatchInjectError <- err
|
|
||||||
},
|
|
||||||
func(obj runtime.Object, action string) error {
|
|
||||||
return registrytest.EmitObject(fakeClient, obj, action)
|
|
||||||
},
|
|
||||||
// matching labels
|
// matching labels
|
||||||
[]labels.Set{
|
[]labels.Set{
|
||||||
{"name": "foo"},
|
{"name": "foo"},
|
||||||
@ -199,7 +165,6 @@ func TestWatchNodes(t *testing.T) {
|
|||||||
[]fields.Set{
|
[]fields.Set{
|
||||||
{"metadata.name": "bar"},
|
{"metadata.name": "bar"},
|
||||||
},
|
},
|
||||||
registrytest.WatchActions,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,9 +20,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/rest/resttest"
|
|
||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
"k8s.io/kubernetes/pkg/registry/namespace"
|
|
||||||
"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"
|
||||||
@ -46,34 +44,14 @@ func validNewNamespace() *api.Namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func validChangedNamespace() *api.Namespace {
|
|
||||||
namespace := validNewNamespace()
|
|
||||||
namespace.ResourceVersion = "1"
|
|
||||||
namespace.Labels = map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
}
|
|
||||||
return namespace
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStorage(t *testing.T) {
|
|
||||||
storage, _ := newStorage(t)
|
|
||||||
namespace.NewRegistry(storage)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
namespace := validNewNamespace()
|
namespace := validNewNamespace()
|
||||||
namespace.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
|
namespace.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
|
||||||
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"},
|
||||||
@ -137,24 +115,14 @@ func TestNamespaceDecode(t *testing.T) {
|
|||||||
|
|
||||||
func TestGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
namespace := validNewNamespace()
|
test.TestGet(validNewNamespace())
|
||||||
test.TestGet(namespace)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestList(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
test.TestList(validNewNamespace())
|
||||||
namespace := validNewNamespace()
|
|
||||||
test.TestList(
|
|
||||||
namespace,
|
|
||||||
func(objects []runtime.Object) []runtime.Object {
|
|
||||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteNamespace(t *testing.T) {
|
func TestDeleteNamespace(t *testing.T) {
|
||||||
|
@ -70,18 +70,12 @@ func validChangedPersistentVolume() *api.PersistentVolume {
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
pv := validNewPersistentVolume("foo")
|
pv := validNewPersistentVolume("foo")
|
||||||
pv.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
|
pv.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
|
||||||
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!"},
|
||||||
@ -91,19 +85,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewPersistentVolume("foo"),
|
validNewPersistentVolume("foo"),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*api.PersistentVolume)
|
object := obj.(*api.PersistentVolume)
|
||||||
@ -143,26 +128,16 @@ func TestDelete(t *testing.T) {
|
|||||||
test.TestDelete(createFn, gracefulSetFn)
|
test.TestDelete(createFn, gracefulSetFn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetPersistentVolumes(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
persistentVolume := validNewPersistentVolume("foo")
|
test.TestGet(validNewPersistentVolume("foo"))
|
||||||
test.TestGet(persistentVolume)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListPersistentVolumes(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
test.TestList(validNewPersistentVolume("foo"))
|
||||||
persistentVolume := validNewPersistentVolume("foo")
|
|
||||||
test.TestList(
|
|
||||||
persistentVolume,
|
|
||||||
func(objects []runtime.Object) []runtime.Object {
|
|
||||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPersistentVolumesDecode(t *testing.T) {
|
func TestPersistentVolumesDecode(t *testing.T) {
|
||||||
|
@ -67,18 +67,12 @@ func validChangedPersistentVolumeClaim() *api.PersistentVolumeClaim {
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
pv := validNewPersistentVolumeClaim("foo", api.NamespaceDefault)
|
pv := validNewPersistentVolumeClaim("foo", api.NamespaceDefault)
|
||||||
pv.ObjectMeta = api.ObjectMeta{}
|
pv.ObjectMeta = api.ObjectMeta{}
|
||||||
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!"},
|
||||||
@ -88,19 +82,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewPersistentVolumeClaim("foo", api.NamespaceDefault),
|
validNewPersistentVolumeClaim("foo", api.NamespaceDefault),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*api.PersistentVolumeClaim)
|
object := obj.(*api.PersistentVolumeClaim)
|
||||||
@ -142,26 +127,16 @@ func TestDelete(t *testing.T) {
|
|||||||
test.TestDelete(createFn, gracefulSetFn)
|
test.TestDelete(createFn, gracefulSetFn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetPersistentVolumeClaims(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
claim := validNewPersistentVolumeClaim("foo", api.NamespaceDefault)
|
test.TestGet(validNewPersistentVolumeClaim("foo", api.NamespaceDefault))
|
||||||
test.TestGet(claim)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListPersistentVolumeClaims(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
test.TestList(validNewPersistentVolumeClaim("foo", api.NamespaceDefault))
|
||||||
claim := validNewPersistentVolumeClaim("foo", api.NamespaceDefault)
|
|
||||||
test.TestList(
|
|
||||||
claim,
|
|
||||||
func(objects []runtime.Object) []runtime.Object {
|
|
||||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPersistentVolumeClaimsDecode(t *testing.T) {
|
func TestPersistentVolumeClaimsDecode(t *testing.T) {
|
||||||
|
@ -53,7 +53,7 @@ type PodStorage struct {
|
|||||||
|
|
||||||
// REST implements a RESTStorage for pods against etcd
|
// REST implements a RESTStorage for pods against etcd
|
||||||
type REST struct {
|
type REST struct {
|
||||||
etcdgeneric.Etcd
|
*etcdgeneric.Etcd
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStorage returns a RESTStorage object that will work against pods.
|
// NewStorage returns a RESTStorage object that will work against pods.
|
||||||
@ -92,19 +92,19 @@ func NewStorage(s storage.Interface, useCacher bool, k client.ConnectionInfoGett
|
|||||||
},
|
},
|
||||||
EndpointName: "pods",
|
EndpointName: "pods",
|
||||||
|
|
||||||
|
CreateStrategy: pod.Strategy,
|
||||||
|
UpdateStrategy: pod.Strategy,
|
||||||
|
DeleteStrategy: pod.Strategy,
|
||||||
|
ReturnDeletedObject: true,
|
||||||
|
|
||||||
Storage: storageInterface,
|
Storage: storageInterface,
|
||||||
}
|
}
|
||||||
statusStore := *store
|
statusStore := *store
|
||||||
|
|
||||||
store.CreateStrategy = pod.Strategy
|
|
||||||
store.UpdateStrategy = pod.Strategy
|
|
||||||
store.DeleteStrategy = pod.Strategy
|
|
||||||
store.ReturnDeletedObject = true
|
|
||||||
|
|
||||||
statusStore.UpdateStrategy = pod.StatusStrategy
|
statusStore.UpdateStrategy = pod.StatusStrategy
|
||||||
|
|
||||||
return PodStorage{
|
return PodStorage{
|
||||||
Pod: &REST{*store},
|
Pod: &REST{store},
|
||||||
Binding: &BindingREST{store: store},
|
Binding: &BindingREST{store: store},
|
||||||
Status: &StatusREST{store: &statusStore},
|
Status: &StatusREST{store: &statusStore},
|
||||||
Log: &LogREST{store: store, kubeletConn: k},
|
Log: &LogREST{store: store, kubeletConn: k},
|
||||||
|
@ -82,7 +82,7 @@ func validChangedPod() *api.Pod {
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, _, _, fakeClient := newStorage(t)
|
storage, _, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
pod := validNewPod()
|
pod := validNewPod()
|
||||||
pod.ObjectMeta = api.ObjectMeta{}
|
pod.ObjectMeta = api.ObjectMeta{}
|
||||||
// Make an invalid pod with an an incorrect label.
|
// Make an invalid pod with an an incorrect label.
|
||||||
@ -94,12 +94,6 @@ 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{
|
||||||
@ -113,19 +107,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, _, _, fakeClient := newStorage(t)
|
storage, _, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewPod(),
|
validNewPod(),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*api.Pod)
|
object := obj.(*api.Pod)
|
||||||
@ -383,40 +368,23 @@ func TestDeletePod(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, _, _, fakeClient := newStorage(t)
|
storage, _, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestGet(validNewPod())
|
test.TestGet(validNewPod())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdList(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
storage, _, _, fakeClient := newStorage(t)
|
storage, _, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
key := etcdtest.AddPrefix(storage.Etcd.KeyRootFunc(test.TestContext()))
|
test.TestList(validNewPod())
|
||||||
test.TestList(
|
|
||||||
validNewPod(),
|
|
||||||
func(objects []runtime.Object) []runtime.Object {
|
|
||||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdWatch(t *testing.T) {
|
func TestWatch(t *testing.T) {
|
||||||
storage, _, _, fakeClient := newStorage(t)
|
storage, _, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestWatch(
|
test.TestWatch(
|
||||||
validNewPod(),
|
validNewPod(),
|
||||||
func() {
|
|
||||||
fakeClient.WaitForWatchCompletion()
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
fakeClient.WatchInjectError <- err
|
|
||||||
},
|
|
||||||
func(obj runtime.Object, action string) error {
|
|
||||||
return registrytest.EmitObject(fakeClient, obj, action)
|
|
||||||
},
|
|
||||||
// matching labels
|
// matching labels
|
||||||
[]labels.Set{},
|
[]labels.Set{},
|
||||||
// not matching labels
|
// not matching labels
|
||||||
@ -431,7 +399,6 @@ func TestEtcdWatch(t *testing.T) {
|
|||||||
[]fields.Set{
|
[]fields.Set{
|
||||||
{"metadata.name": "bar"},
|
{"metadata.name": "bar"},
|
||||||
},
|
},
|
||||||
registrytest.WatchActions,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,13 +28,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type REST struct {
|
type REST struct {
|
||||||
etcdgeneric.Etcd
|
*etcdgeneric.Etcd
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewREST returns a RESTStorage object that will work against pod templates.
|
// NewREST returns a RESTStorage object that will work against pod templates.
|
||||||
func NewREST(s storage.Interface) *REST {
|
func NewREST(s storage.Interface) *REST {
|
||||||
prefix := "/podtemplates"
|
prefix := "/podtemplates"
|
||||||
store := etcdgeneric.Etcd{
|
store := &etcdgeneric.Etcd{
|
||||||
NewFunc: func() runtime.Object { return &api.PodTemplate{} },
|
NewFunc: func() runtime.Object { return &api.PodTemplate{} },
|
||||||
NewListFunc: func() runtime.Object { return &api.PodTemplateList{} },
|
NewListFunc: func() runtime.Object { return &api.PodTemplateList{} },
|
||||||
KeyRootFunc: func(ctx api.Context) string {
|
KeyRootFunc: func(ctx api.Context) string {
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"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/runtime"
|
||||||
"k8s.io/kubernetes/pkg/tools"
|
"k8s.io/kubernetes/pkg/tools"
|
||||||
@ -60,18 +59,12 @@ func validNewPodTemplate(name string) *api.PodTemplate {
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
pod := validNewPodTemplate("foo")
|
pod := validNewPodTemplate("foo")
|
||||||
pod.ObjectMeta = api.ObjectMeta{}
|
pod.ObjectMeta = api.ObjectMeta{}
|
||||||
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{},
|
||||||
@ -81,19 +74,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
//valid
|
//valid
|
||||||
validNewPodTemplate("foo"),
|
validNewPodTemplate("foo"),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*api.PodTemplate)
|
object := obj.(*api.PodTemplate)
|
||||||
@ -102,3 +86,15 @@ func TestUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGet(t *testing.T) {
|
||||||
|
storage, fakeClient := newStorage(t)
|
||||||
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
|
test.TestGet(validNewPodTemplate("foo"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestList(t *testing.T) {
|
||||||
|
storage, fakeClient := newStorage(t)
|
||||||
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
|
test.TestList(validNewPodTemplate("foo"))
|
||||||
|
}
|
||||||
|
@ -22,7 +22,11 @@ import (
|
|||||||
"github.com/coreos/go-etcd/etcd"
|
"github.com/coreos/go-etcd/etcd"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/api/rest/resttest"
|
||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
|
"k8s.io/kubernetes/pkg/fields"
|
||||||
|
"k8s.io/kubernetes/pkg/labels"
|
||||||
|
etcdgeneric "k8s.io/kubernetes/pkg/registry/generic/etcd"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
"k8s.io/kubernetes/pkg/storage"
|
"k8s.io/kubernetes/pkg/storage"
|
||||||
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
|
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
|
||||||
@ -37,12 +41,166 @@ func NewEtcdStorage(t *testing.T) (storage.Interface, *tools.FakeEtcdClient) {
|
|||||||
return etcdStorage, fakeClient
|
return etcdStorage, fakeClient
|
||||||
}
|
}
|
||||||
|
|
||||||
var WatchActions = []string{etcdstorage.EtcdCreate, etcdstorage.EtcdSet, etcdstorage.EtcdCAS, etcdstorage.EtcdDelete}
|
type Tester struct {
|
||||||
|
tester *resttest.Tester
|
||||||
|
fakeClient *tools.FakeEtcdClient
|
||||||
|
storage *etcdgeneric.Etcd
|
||||||
|
}
|
||||||
|
type UpdateFunc func(runtime.Object) runtime.Object
|
||||||
|
|
||||||
type keyFunc func(api.Context, string) (string, error)
|
func New(t *testing.T, fakeClient *tools.FakeEtcdClient, storage *etcdgeneric.Etcd) *Tester {
|
||||||
type newFunc func() runtime.Object
|
return &Tester{
|
||||||
|
tester: resttest.New(t, storage, fakeClient.SetError),
|
||||||
|
fakeClient: fakeClient,
|
||||||
|
storage: storage,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func EmitObject(fakeClient *tools.FakeEtcdClient, obj runtime.Object, action string) error {
|
func (t *Tester) TestNamespace() string {
|
||||||
|
return t.tester.TestNamespace()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) ClusterScope() *Tester {
|
||||||
|
t.tester = t.tester.ClusterScope()
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) AllowCreateOnUpdate() *Tester {
|
||||||
|
t.tester = t.tester.AllowCreateOnUpdate()
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) GeneratesName() *Tester {
|
||||||
|
t.tester = t.tester.GeneratesName()
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) TestCreate(valid runtime.Object, invalid ...runtime.Object) {
|
||||||
|
t.tester.TestCreate(
|
||||||
|
valid,
|
||||||
|
t.setObject,
|
||||||
|
t.getObject,
|
||||||
|
invalid...,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) TestUpdate(valid runtime.Object, validUpdateFunc UpdateFunc, invalidUpdateFunc ...UpdateFunc) {
|
||||||
|
var invalidFuncs []resttest.UpdateFunc
|
||||||
|
for _, f := range invalidUpdateFunc {
|
||||||
|
invalidFuncs = append(invalidFuncs, resttest.UpdateFunc(f))
|
||||||
|
}
|
||||||
|
t.tester.TestUpdate(
|
||||||
|
valid,
|
||||||
|
t.setObject,
|
||||||
|
t.setResourceVersion,
|
||||||
|
t.getObject,
|
||||||
|
resttest.UpdateFunc(validUpdateFunc),
|
||||||
|
invalidFuncs...,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) TestGet(valid runtime.Object) {
|
||||||
|
t.tester.TestGet(valid)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) TestList(valid runtime.Object) {
|
||||||
|
t.tester.TestList(
|
||||||
|
valid,
|
||||||
|
t.setObjectsForList,
|
||||||
|
t.setResourceVersion,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) TestWatch(valid runtime.Object, labelsPass, labelsFail []labels.Set, fieldsPass, fieldsFail []fields.Set) {
|
||||||
|
t.tester.TestWatch(
|
||||||
|
valid,
|
||||||
|
t.fakeClient.WaitForWatchCompletion,
|
||||||
|
t.injectWatchError,
|
||||||
|
t.emitObject,
|
||||||
|
labelsPass,
|
||||||
|
labelsFail,
|
||||||
|
fieldsPass,
|
||||||
|
fieldsFail,
|
||||||
|
[]string{etcdstorage.EtcdCreate, etcdstorage.EtcdSet, etcdstorage.EtcdCAS, etcdstorage.EtcdDelete},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// Helper functions
|
||||||
|
|
||||||
|
func (t *Tester) getObject(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
||||||
|
meta, err := api.ObjectMetaFor(obj)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
key, err := t.storage.KeyFunc(ctx, meta.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
key = etcdtest.AddPrefix(key)
|
||||||
|
resp, err := t.fakeClient.Get(key, false, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := t.storage.NewFunc()
|
||||||
|
if err := testapi.Codec().DecodeInto([]byte(resp.Node.Value), result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) setObject(ctx api.Context, obj runtime.Object) error {
|
||||||
|
meta, err := api.ObjectMetaFor(obj)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
key, err := t.storage.KeyFunc(ctx, meta.Name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
key = etcdtest.AddPrefix(key)
|
||||||
|
_, err = t.fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), obj), 0)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) setObjectsForList(objects []runtime.Object) []runtime.Object {
|
||||||
|
result := make([]runtime.Object, len(objects))
|
||||||
|
key := etcdtest.AddPrefix(t.storage.KeyRootFunc(t.tester.TestContext()))
|
||||||
|
|
||||||
|
if len(objects) > 0 {
|
||||||
|
nodes := make([]*etcd.Node, len(objects))
|
||||||
|
for i, obj := range objects {
|
||||||
|
encoded := runtime.EncodeOrDie(testapi.Codec(), obj)
|
||||||
|
decoded, _ := testapi.Codec().Decode([]byte(encoded))
|
||||||
|
nodes[i] = &etcd.Node{Value: encoded}
|
||||||
|
result[i] = decoded
|
||||||
|
}
|
||||||
|
t.fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||||
|
R: &etcd.Response{
|
||||||
|
Node: &etcd.Node{
|
||||||
|
Nodes: nodes,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
E: nil,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||||
|
R: &etcd.Response{},
|
||||||
|
E: t.fakeClient.NewError(tools.EtcdErrorCodeNotFound),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) setResourceVersion(resourceVersion uint64) {
|
||||||
|
t.fakeClient.ChangeIndex = resourceVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) injectWatchError(err error) {
|
||||||
|
t.fakeClient.WatchInjectError <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tester) emitObject(obj runtime.Object, action string) error {
|
||||||
encoded, err := testapi.Codec().Encode(obj)
|
encoded, err := testapi.Codec().Encode(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -54,76 +212,10 @@ func EmitObject(fakeClient *tools.FakeEtcdClient, obj runtime.Object, action str
|
|||||||
if action == etcdstorage.EtcdDelete {
|
if action == etcdstorage.EtcdDelete {
|
||||||
prevNode = node
|
prevNode = node
|
||||||
}
|
}
|
||||||
fakeClient.WatchResponse <- &etcd.Response{
|
t.fakeClient.WatchResponse <- &etcd.Response{
|
||||||
Action: action,
|
Action: action,
|
||||||
Node: node,
|
Node: node,
|
||||||
PrevNode: prevNode,
|
PrevNode: prevNode,
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|
||||||
result := make([]runtime.Object, len(objects))
|
|
||||||
if len(objects) > 0 {
|
|
||||||
nodes := make([]*etcd.Node, len(objects))
|
|
||||||
for i, obj := range objects {
|
|
||||||
encoded := runtime.EncodeOrDie(testapi.Codec(), obj)
|
|
||||||
decoded, _ := testapi.Codec().Decode([]byte(encoded))
|
|
||||||
nodes[i] = &etcd.Node{Value: encoded}
|
|
||||||
result[i] = decoded
|
|
||||||
}
|
|
||||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
||||||
R: &etcd.Response{
|
|
||||||
Node: &etcd.Node{
|
|
||||||
Nodes: nodes,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
E: nil,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
||||||
R: &etcd.Response{},
|
|
||||||
E: fakeClient.NewError(tools.EtcdErrorCodeNotFound),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetResourceVersion(fakeClient *tools.FakeEtcdClient, resourceVersion uint64) {
|
|
||||||
fakeClient.ChangeIndex = resourceVersion
|
|
||||||
}
|
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/resource"
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
"k8s.io/kubernetes/pkg/api/rest/resttest"
|
|
||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
"k8s.io/kubernetes/pkg/fields"
|
"k8s.io/kubernetes/pkg/fields"
|
||||||
"k8s.io/kubernetes/pkg/labels"
|
"k8s.io/kubernetes/pkg/labels"
|
||||||
@ -60,29 +59,14 @@ func validNewResourceQuota() *api.ResourceQuota {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func validChangedResourceQuota() *api.ResourceQuota {
|
|
||||||
resourcequota := validNewResourceQuota()
|
|
||||||
resourcequota.ResourceVersion = "1"
|
|
||||||
resourcequota.Labels = map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
}
|
|
||||||
return resourcequota
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
resourcequota := validNewResourceQuota()
|
resourcequota := validNewResourceQuota()
|
||||||
resourcequota.ObjectMeta = api.ObjectMeta{}
|
resourcequota.ObjectMeta = api.ObjectMeta{}
|
||||||
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_"},
|
||||||
@ -177,40 +161,23 @@ func TestDeleteResourceQuota(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestGet(validNewResourceQuota())
|
test.TestGet(validNewResourceQuota())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdList(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
key := etcdtest.AddPrefix(storage.Etcd.KeyRootFunc(test.TestContext()))
|
test.TestList(validNewResourceQuota())
|
||||||
test.TestList(
|
|
||||||
validNewResourceQuota(),
|
|
||||||
func(objects []runtime.Object) []runtime.Object {
|
|
||||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdWatch(t *testing.T) {
|
func TestWatch(t *testing.T) {
|
||||||
storage, _, fakeClient := newStorage(t)
|
storage, _, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestWatch(
|
test.TestWatch(
|
||||||
validNewResourceQuota(),
|
validNewResourceQuota(),
|
||||||
func() {
|
|
||||||
fakeClient.WaitForWatchCompletion()
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
fakeClient.WatchInjectError <- err
|
|
||||||
},
|
|
||||||
func(obj runtime.Object, action string) error {
|
|
||||||
return registrytest.EmitObject(fakeClient, obj, action)
|
|
||||||
},
|
|
||||||
// matching labels
|
// matching labels
|
||||||
[]labels.Set{},
|
[]labels.Set{},
|
||||||
// not matching labels
|
// not matching labels
|
||||||
@ -225,7 +192,6 @@ func TestEtcdWatch(t *testing.T) {
|
|||||||
[]fields.Set{
|
[]fields.Set{
|
||||||
{"metadata.name": "bar"},
|
{"metadata.name": "bar"},
|
||||||
},
|
},
|
||||||
registrytest.WatchActions,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"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/runtime"
|
||||||
"k8s.io/kubernetes/pkg/tools"
|
"k8s.io/kubernetes/pkg/tools"
|
||||||
@ -45,18 +44,12 @@ func validNewSecret(name string) *api.Secret {
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
secret := validNewSecret("foo")
|
secret := validNewSecret("foo")
|
||||||
secret.ObjectMeta = api.ObjectMeta{GenerateName: "foo-"}
|
secret.ObjectMeta = api.ObjectMeta{GenerateName: "foo-"}
|
||||||
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{
|
||||||
@ -72,19 +65,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewSecret("foo"),
|
validNewSecret("foo"),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*api.Secret)
|
object := obj.(*api.Secret)
|
||||||
@ -93,3 +77,15 @@ func TestUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGet(t *testing.T) {
|
||||||
|
storage, fakeClient := newStorage(t)
|
||||||
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
|
test.TestGet(validNewSecret("foo"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestList(t *testing.T) {
|
||||||
|
storage, fakeClient := newStorage(t)
|
||||||
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
|
test.TestList(validNewSecret("foo"))
|
||||||
|
}
|
||||||
|
@ -30,13 +30,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type REST struct {
|
type REST struct {
|
||||||
etcdgeneric.Etcd
|
*etcdgeneric.Etcd
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewREST returns a RESTStorage object that will work against services.
|
// NewREST returns a RESTStorage object that will work against services.
|
||||||
func NewREST(s storage.Interface) *REST {
|
func NewREST(s storage.Interface) *REST {
|
||||||
prefix := "/services/specs"
|
prefix := "/services/specs"
|
||||||
store := etcdgeneric.Etcd{
|
store := &etcdgeneric.Etcd{
|
||||||
NewFunc: func() runtime.Object { return &api.Service{} },
|
NewFunc: func() runtime.Object { return &api.Service{} },
|
||||||
NewListFunc: func() runtime.Object { return &api.ServiceList{} },
|
NewListFunc: func() runtime.Object { return &api.ServiceList{} },
|
||||||
KeyRootFunc: func(ctx api.Context) string {
|
KeyRootFunc: func(ctx api.Context) string {
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"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"
|
||||||
@ -56,18 +55,12 @@ func validService() *api.Service {
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
validService := validService()
|
validService := validService()
|
||||||
validService.ObjectMeta = api.ObjectMeta{}
|
validService.ObjectMeta = api.ObjectMeta{}
|
||||||
test.TestCreate(
|
test.TestCreate(
|
||||||
// valid
|
// valid
|
||||||
validService,
|
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
|
// invalid
|
||||||
&api.Service{
|
&api.Service{
|
||||||
Spec: api.ServiceSpec{},
|
Spec: api.ServiceSpec{},
|
||||||
@ -91,19 +84,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError).AllowCreateOnUpdate()
|
test := registrytest.New(t, fakeClient, storage.Etcd).AllowCreateOnUpdate()
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validService(),
|
validService(),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*api.Service)
|
object := obj.(*api.Service)
|
||||||
@ -122,20 +106,23 @@ func TestUpdate(t *testing.T) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGet(t *testing.T) {
|
||||||
|
storage, fakeClient := newStorage(t)
|
||||||
|
test := registrytest.New(t, fakeClient, storage.Etcd).AllowCreateOnUpdate()
|
||||||
|
test.TestGet(validService())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestList(t *testing.T) {
|
||||||
|
storage, fakeClient := newStorage(t)
|
||||||
|
test := registrytest.New(t, fakeClient, storage.Etcd).AllowCreateOnUpdate()
|
||||||
|
test.TestList(validService())
|
||||||
|
}
|
||||||
|
|
||||||
func TestWatch(t *testing.T) {
|
func TestWatch(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestWatch(
|
test.TestWatch(
|
||||||
validService(),
|
validService(),
|
||||||
func() {
|
|
||||||
fakeClient.WaitForWatchCompletion()
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
fakeClient.WatchInjectError <- err
|
|
||||||
},
|
|
||||||
func(obj runtime.Object, action string) error {
|
|
||||||
return registrytest.EmitObject(fakeClient, obj, action)
|
|
||||||
},
|
|
||||||
// matching labels
|
// matching labels
|
||||||
[]labels.Set{},
|
[]labels.Set{},
|
||||||
// not matching labels
|
// not matching labels
|
||||||
@ -150,6 +137,5 @@ func TestWatch(t *testing.T) {
|
|||||||
[]fields.Set{
|
[]fields.Set{
|
||||||
{"metadata.name": "bar"},
|
{"metadata.name": "bar"},
|
||||||
},
|
},
|
||||||
registrytest.WatchActions,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"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/runtime"
|
||||||
"k8s.io/kubernetes/pkg/tools"
|
"k8s.io/kubernetes/pkg/tools"
|
||||||
@ -43,18 +42,12 @@ func validNewServiceAccount(name string) *api.ServiceAccount {
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
serviceAccount := validNewServiceAccount("foo")
|
serviceAccount := validNewServiceAccount("foo")
|
||||||
serviceAccount.ObjectMeta = api.ObjectMeta{GenerateName: "foo-"}
|
serviceAccount.ObjectMeta = api.ObjectMeta{GenerateName: "foo-"}
|
||||||
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{
|
||||||
@ -65,19 +58,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewServiceAccount("foo"),
|
validNewServiceAccount("foo"),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*api.ServiceAccount)
|
object := obj.(*api.ServiceAccount)
|
||||||
@ -86,3 +70,15 @@ func TestUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGet(t *testing.T) {
|
||||||
|
storage, fakeClient := newStorage(t)
|
||||||
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
|
test.TestGet(validNewServiceAccount("foo"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestList(t *testing.T) {
|
||||||
|
storage, fakeClient := newStorage(t)
|
||||||
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
|
test.TestList(validNewServiceAccount("foo"))
|
||||||
|
}
|
||||||
|
@ -23,9 +23,8 @@ import (
|
|||||||
"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"
|
||||||
"k8s.io/kubernetes/pkg/expapi"
|
"k8s.io/kubernetes/pkg/expapi"
|
||||||
"k8s.io/kubernetes/pkg/expapi/v1"
|
// Ensure that expapi/v1 package is initialized.
|
||||||
"k8s.io/kubernetes/pkg/fields"
|
_ "k8s.io/kubernetes/pkg/expapi/v1"
|
||||||
"k8s.io/kubernetes/pkg/labels"
|
|
||||||
"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"
|
||||||
@ -34,11 +33,6 @@ import (
|
|||||||
"github.com/coreos/go-etcd/etcd"
|
"github.com/coreos/go-etcd/etcd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
// Ensure that expapi/v1 packege is used, so that it will get initialized and register HorizontalPodAutoscaler object.
|
|
||||||
_ = v1.ThirdPartyResource{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
||||||
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
|
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
|
||||||
return NewREST(etcdStorage), fakeClient
|
return NewREST(etcdStorage), fakeClient
|
||||||
@ -60,18 +54,12 @@ func validNewThirdPartyResource(name string) *expapi.ThirdPartyResource {
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
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{},
|
||||||
)
|
)
|
||||||
@ -79,19 +67,10 @@ func TestCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewThirdPartyResource("foo"),
|
validNewThirdPartyResource("foo"),
|
||||||
func(ctx api.Context, obj runtime.Object) error {
|
|
||||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
func(resourceVersion uint64) {
|
|
||||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
|
||||||
},
|
|
||||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
|
||||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
|
||||||
},
|
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*expapi.ThirdPartyResource)
|
object := obj.(*expapi.ThirdPartyResource)
|
||||||
@ -130,73 +109,12 @@ func TestDelete(t *testing.T) {
|
|||||||
|
|
||||||
func TestGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := resttest.New(t, storage, fakeClient.SetError)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
rsrc := validNewThirdPartyResource("foo")
|
test.TestGet(validNewThirdPartyResource("foo"))
|
||||||
test.TestGet(rsrc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEmptyList(t *testing.T) {
|
|
||||||
ctx := api.NewDefaultContext()
|
|
||||||
registry, fakeClient := newStorage(t)
|
|
||||||
fakeClient.ChangeIndex = 1
|
|
||||||
key := registry.KeyRootFunc(ctx)
|
|
||||||
key = etcdtest.AddPrefix(key)
|
|
||||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
||||||
R: &etcd.Response{},
|
|
||||||
E: fakeClient.NewError(tools.EtcdErrorCodeNotFound),
|
|
||||||
}
|
|
||||||
rsrcList, err := registry.List(ctx, labels.Everything(), fields.Everything())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
if len(rsrcList.(*expapi.ThirdPartyResourceList).Items) != 0 {
|
|
||||||
t.Errorf("Unexpected non-zero autoscaler list: %#v", rsrcList)
|
|
||||||
}
|
|
||||||
if rsrcList.(*expapi.ThirdPartyResourceList).ResourceVersion != "1" {
|
|
||||||
t.Errorf("Unexpected resource version: %#v", rsrcList)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestList(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
ctx := api.NewDefaultContext()
|
storage, fakeClient := newStorage(t)
|
||||||
registry, fakeClient := newStorage(t)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
fakeClient.ChangeIndex = 1
|
test.TestList(validNewThirdPartyResource("foo"))
|
||||||
key := registry.KeyRootFunc(ctx)
|
|
||||||
key = etcdtest.AddPrefix(key)
|
|
||||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
|
||||||
R: &etcd.Response{
|
|
||||||
Node: &etcd.Node{
|
|
||||||
Nodes: []*etcd.Node{
|
|
||||||
{
|
|
||||||
Value: runtime.EncodeOrDie(testapi.Codec(), &expapi.ThirdPartyResource{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Value: runtime.EncodeOrDie(testapi.Codec(), &expapi.ThirdPartyResource{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "bar"},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
obj, err := registry.List(ctx, labels.Everything(), fields.Everything())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error %v", err)
|
|
||||||
}
|
|
||||||
rsrcList := obj.(*expapi.ThirdPartyResourceList)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(rsrcList.Items) != 2 {
|
|
||||||
t.Errorf("Unexpected ThirdPartyResource list: %#v", rsrcList)
|
|
||||||
}
|
|
||||||
if rsrcList.Items[0].Name != "foo" {
|
|
||||||
t.Errorf("Unexpected ThirdPartyResource: %#v", rsrcList.Items[0])
|
|
||||||
}
|
|
||||||
if rsrcList.Items[1].Name != "bar" {
|
|
||||||
t.Errorf("Unexpected ThirdPartyResource: %#v", rsrcList.Items[1])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user