mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +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) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
controller := validNewController()
|
||||
controller.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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)
|
||||
&api.ReplicationController{
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
@ -104,20 +98,11 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
validNewController(),
|
||||
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
|
||||
// valid updateFunc
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
object := obj.(*api.ReplicationController)
|
||||
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)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestGet(validNewController())
|
||||
}
|
||||
|
||||
func TestEtcdListControllers(t *testing.T) {
|
||||
func TestList(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
||||
test.TestList(
|
||||
validNewController(),
|
||||
func(objects []runtime.Object) []runtime.Object {
|
||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
||||
},
|
||||
func(resourceVersion uint64) {
|
||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
||||
})
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestList(validNewController())
|
||||
}
|
||||
|
||||
func TestWatchControllers(t *testing.T) {
|
||||
func TestWatch(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestWatch(
|
||||
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
|
||||
[]labels.Set{
|
||||
{"a": "b"},
|
||||
@ -248,7 +216,6 @@ func TestWatchControllers(t *testing.T) {
|
||||
{"status.replicas": "10", "metadata.name": "foo"},
|
||||
{"status.replicas": "0", "metadata.name": "bar"},
|
||||
},
|
||||
registrytest.WatchActions,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -37,17 +37,6 @@ func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
||||
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 {
|
||||
return &expapi.Daemon{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
@ -80,18 +69,12 @@ var validDaemon = validNewDaemon()
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
daemon := validNewDaemon()
|
||||
daemon.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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)
|
||||
&expapi.Daemon{
|
||||
Spec: expapi.DaemonSpec{
|
||||
@ -104,19 +87,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
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)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestGet(validNewDaemon())
|
||||
}
|
||||
|
||||
func TestEtcdListControllers(t *testing.T) {
|
||||
func TestList(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
||||
test.TestList(
|
||||
validNewDaemon(),
|
||||
func(objects []runtime.Object) []runtime.Object {
|
||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
||||
},
|
||||
func(resourceVersion uint64) {
|
||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
||||
})
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestList(validNewDaemon())
|
||||
}
|
||||
|
||||
func TestWatchControllers(t *testing.T) {
|
||||
func TestWatch(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestWatch(
|
||||
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
|
||||
[]labels.Set{
|
||||
{"a": "b"},
|
||||
@ -199,11 +156,10 @@ func TestWatchControllers(t *testing.T) {
|
||||
{"metadata.name": "bar"},
|
||||
{"name": "foo"},
|
||||
},
|
||||
registrytest.WatchActions,
|
||||
)
|
||||
}
|
||||
|
||||
func TestEtcdDeleteController(t *testing.T) {
|
||||
func TestEtcdDeleteDaemon(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
storage, fakeClient := newStorage(t)
|
||||
key, err := storage.KeyFunc(ctx, validDaemon.Name)
|
||||
@ -248,7 +204,7 @@ func TestDelete(t *testing.T) {
|
||||
return dc
|
||||
}
|
||||
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.
|
||||
if fakeClient.Data[key].R.Node != nil {
|
||||
return true
|
||||
|
@ -18,7 +18,6 @@ package etcd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@ -27,19 +26,12 @@ import (
|
||||
"k8s.io/kubernetes/pkg/expapi"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
etcdgeneric "k8s.io/kubernetes/pkg/registry/generic/etcd"
|
||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
|
||||
"k8s.io/kubernetes/pkg/tools"
|
||||
"k8s.io/kubernetes/pkg/tools/etcdtest"
|
||||
)
|
||||
|
||||
const (
|
||||
PASS = iota
|
||||
FAIL
|
||||
)
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
||||
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
|
||||
return NewREST(etcdStorage), fakeClient
|
||||
@ -77,18 +69,12 @@ var validDeployment = *validNewDeployment()
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
deployment := validNewDeployment()
|
||||
deployment.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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)
|
||||
&expapi.Deployment{
|
||||
Spec: expapi.DeploymentSpec{
|
||||
@ -101,19 +87,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
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)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestGet(validNewDeployment())
|
||||
}
|
||||
|
||||
func TestEtcdList(t *testing.T) {
|
||||
func TestList(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
||||
test.TestList(
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestList(validNewDeployment())
|
||||
}
|
||||
|
||||
func TestWatch(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestWatch(
|
||||
validNewDeployment(),
|
||||
func(objects []runtime.Object) []runtime.Object {
|
||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
||||
// matching labels
|
||||
[]labels.Set{},
|
||||
// not matching labels
|
||||
[]labels.Set{
|
||||
{"a": "c"},
|
||||
{"foo": "bar"},
|
||||
},
|
||||
func(resourceVersion uint64) {
|
||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
||||
})
|
||||
// matching fields
|
||||
[]fields.Set{
|
||||
{"metadata.name": "foo"},
|
||||
},
|
||||
// not matchin fields
|
||||
[]fields.Set{
|
||||
{"metadata.name": "bar"},
|
||||
{"name": "foo"},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
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) {
|
||||
ctx := api.NewDefaultContext()
|
||||
storage, fakeClient := newStorage(t)
|
||||
|
@ -61,18 +61,12 @@ func validChangedEndpoints() *api.Endpoints {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
endpoints := validNewEndpoints()
|
||||
endpoints.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&api.Endpoints{
|
||||
ObjectMeta: api.ObjectMeta{Name: "_-a123-a_"},
|
||||
@ -82,19 +76,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).AllowCreateOnUpdate()
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).AllowCreateOnUpdate()
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
object := obj.(*api.Endpoints)
|
||||
@ -135,26 +120,16 @@ func TestDelete(t *testing.T) {
|
||||
test.TestDelete(createFn, gracefulSetFn)
|
||||
}
|
||||
|
||||
func TestEtcdGetEndpoints(t *testing.T) {
|
||||
func TestGet(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
endpoints := validNewEndpoints()
|
||||
test.TestGet(endpoints)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestGet(validNewEndpoints())
|
||||
}
|
||||
|
||||
func TestEtcdListEndpoints(t *testing.T) {
|
||||
func TestList(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
endpoints := 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)
|
||||
})
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestList(validNewEndpoints())
|
||||
}
|
||||
|
||||
func TestEndpointsDecode(t *testing.T) {
|
||||
|
@ -58,18 +58,12 @@ func validNewHorizontalPodAutoscaler(name string) *expapi.HorizontalPodAutoscale
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
autoscaler := validNewHorizontalPodAutoscaler("foo")
|
||||
autoscaler.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&expapi.HorizontalPodAutoscaler{},
|
||||
)
|
||||
@ -77,19 +71,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
object := obj.(*expapi.HorizontalPodAutoscaler)
|
||||
@ -128,22 +113,12 @@ func TestDelete(t *testing.T) {
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
autoscaler := validNewHorizontalPodAutoscaler("foo")
|
||||
test.TestGet(autoscaler)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestGet(validNewHorizontalPodAutoscaler("foo"))
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
||||
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)
|
||||
})
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestList(validNewHorizontalPodAutoscaler("foo"))
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/api/rest/resttest"
|
||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/tools"
|
||||
@ -58,18 +57,12 @@ func validNewLimitRange() *api.LimitRange {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).GeneratesName()
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).GeneratesName()
|
||||
validLimitRange := validNewLimitRange()
|
||||
validLimitRange.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&api.LimitRange{
|
||||
ObjectMeta: api.ObjectMeta{Name: "_-a123-a_"},
|
||||
@ -79,19 +72,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).AllowCreateOnUpdate()
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).AllowCreateOnUpdate()
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/validation"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
@ -68,10 +70,20 @@ func (limitrangeStrategy) AllowUnconditionalUpdate() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func MatchLimitRange(label labels.Selector, field fields.Selector) generic.Matcher {
|
||||
return &generic.SelectionPredicate{Label: label, Field: field, GetAttrs: getAttrs}
|
||||
func LimitRangeToSelectableFields(limitRange *api.LimitRange) fields.Set {
|
||||
return fields.Set{}
|
||||
}
|
||||
|
||||
func getAttrs(obj runtime.Object) (objLabels labels.Set, objFields fields.Set, err error) {
|
||||
return labels.Set{}, fields.Set{}, nil
|
||||
func MatchLimitRange(label labels.Selector, field fields.Selector) generic.Matcher {
|
||||
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)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
prefix := "/minions"
|
||||
|
||||
|
@ -75,18 +75,12 @@ func validChangedNode() *api.Node {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||
node := validNewNode()
|
||||
node.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&api.Node{
|
||||
ObjectMeta: api.ObjectMeta{Name: "_-a123-a_"},
|
||||
@ -96,19 +90,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
object := obj.(*api.Node)
|
||||
@ -146,42 +131,23 @@ func TestDelete(t *testing.T) {
|
||||
test.TestDelete(createFn, gracefulSetFn)
|
||||
}
|
||||
|
||||
func TestEtcdGetNode(t *testing.T) {
|
||||
func TestGet(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
||||
node := validNewNode()
|
||||
test.TestGet(node)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||
test.TestGet(validNewNode())
|
||||
}
|
||||
|
||||
func TestEtcdListNodes(t *testing.T) {
|
||||
func TestList(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
||||
node := validNewNode()
|
||||
test.TestList(
|
||||
node,
|
||||
func(objects []runtime.Object) []runtime.Object {
|
||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
||||
},
|
||||
func(resourceVersion uint64) {
|
||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
||||
})
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||
test.TestList(validNewNode())
|
||||
}
|
||||
|
||||
func TestWatchNodes(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||
test.TestWatch(
|
||||
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
|
||||
[]labels.Set{
|
||||
{"name": "foo"},
|
||||
@ -199,7 +165,6 @@ func TestWatchNodes(t *testing.T) {
|
||||
[]fields.Set{
|
||||
{"metadata.name": "bar"},
|
||||
},
|
||||
registrytest.WatchActions,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest/resttest"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/registry/namespace"
|
||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"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) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||
namespace := validNewNamespace()
|
||||
namespace.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&api.Namespace{
|
||||
ObjectMeta: api.ObjectMeta{Name: "bad value"},
|
||||
@ -137,24 +115,14 @@ func TestNamespaceDecode(t *testing.T) {
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
||||
namespace := validNewNamespace()
|
||||
test.TestGet(namespace)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||
test.TestGet(validNewNamespace())
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
||||
namespace := validNewNamespace()
|
||||
test.TestList(
|
||||
namespace,
|
||||
func(objects []runtime.Object) []runtime.Object {
|
||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
||||
},
|
||||
func(resourceVersion uint64) {
|
||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
||||
})
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||
test.TestList(validNewNamespace())
|
||||
}
|
||||
|
||||
func TestDeleteNamespace(t *testing.T) {
|
||||
|
@ -70,18 +70,12 @@ func validChangedPersistentVolume() *api.PersistentVolume {
|
||||
|
||||
func TestCreate(t *testing.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.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&api.PersistentVolume{
|
||||
ObjectMeta: api.ObjectMeta{Name: "*BadName!"},
|
||||
@ -91,19 +85,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
object := obj.(*api.PersistentVolume)
|
||||
@ -143,26 +128,16 @@ func TestDelete(t *testing.T) {
|
||||
test.TestDelete(createFn, gracefulSetFn)
|
||||
}
|
||||
|
||||
func TestEtcdGetPersistentVolumes(t *testing.T) {
|
||||
func TestGet(t *testing.T) {
|
||||
storage, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
||||
persistentVolume := validNewPersistentVolume("foo")
|
||||
test.TestGet(persistentVolume)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||
test.TestGet(validNewPersistentVolume("foo"))
|
||||
}
|
||||
|
||||
func TestEtcdListPersistentVolumes(t *testing.T) {
|
||||
func TestList(t *testing.T) {
|
||||
storage, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).ClusterScope()
|
||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
||||
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)
|
||||
})
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).ClusterScope()
|
||||
test.TestList(validNewPersistentVolume("foo"))
|
||||
}
|
||||
|
||||
func TestPersistentVolumesDecode(t *testing.T) {
|
||||
|
@ -67,18 +67,12 @@ func validChangedPersistentVolumeClaim() *api.PersistentVolumeClaim {
|
||||
|
||||
func TestCreate(t *testing.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.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&api.PersistentVolumeClaim{
|
||||
ObjectMeta: api.ObjectMeta{Name: "*BadName!"},
|
||||
@ -88,19 +82,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
object := obj.(*api.PersistentVolumeClaim)
|
||||
@ -142,26 +127,16 @@ func TestDelete(t *testing.T) {
|
||||
test.TestDelete(createFn, gracefulSetFn)
|
||||
}
|
||||
|
||||
func TestEtcdGetPersistentVolumeClaims(t *testing.T) {
|
||||
func TestGet(t *testing.T) {
|
||||
storage, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
claim := validNewPersistentVolumeClaim("foo", api.NamespaceDefault)
|
||||
test.TestGet(claim)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestGet(validNewPersistentVolumeClaim("foo", api.NamespaceDefault))
|
||||
}
|
||||
|
||||
func TestEtcdListPersistentVolumeClaims(t *testing.T) {
|
||||
func TestList(t *testing.T) {
|
||||
storage, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
key := etcdtest.AddPrefix(storage.KeyRootFunc(test.TestContext()))
|
||||
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)
|
||||
})
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestList(validNewPersistentVolumeClaim("foo", api.NamespaceDefault))
|
||||
}
|
||||
|
||||
func TestPersistentVolumeClaimsDecode(t *testing.T) {
|
||||
|
@ -53,7 +53,7 @@ type PodStorage struct {
|
||||
|
||||
// REST implements a RESTStorage for pods against etcd
|
||||
type REST struct {
|
||||
etcdgeneric.Etcd
|
||||
*etcdgeneric.Etcd
|
||||
}
|
||||
|
||||
// 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",
|
||||
|
||||
CreateStrategy: pod.Strategy,
|
||||
UpdateStrategy: pod.Strategy,
|
||||
DeleteStrategy: pod.Strategy,
|
||||
ReturnDeletedObject: true,
|
||||
|
||||
Storage: storageInterface,
|
||||
}
|
||||
statusStore := *store
|
||||
|
||||
store.CreateStrategy = pod.Strategy
|
||||
store.UpdateStrategy = pod.Strategy
|
||||
store.DeleteStrategy = pod.Strategy
|
||||
store.ReturnDeletedObject = true
|
||||
|
||||
statusStore.UpdateStrategy = pod.StatusStrategy
|
||||
|
||||
return PodStorage{
|
||||
Pod: &REST{*store},
|
||||
Pod: &REST{store},
|
||||
Binding: &BindingREST{store: store},
|
||||
Status: &StatusREST{store: &statusStore},
|
||||
Log: &LogREST{store: store, kubeletConn: k},
|
||||
|
@ -82,7 +82,7 @@ func validChangedPod() *api.Pod {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, _, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
pod := validNewPod()
|
||||
pod.ObjectMeta = api.ObjectMeta{}
|
||||
// Make an invalid pod with an an incorrect label.
|
||||
@ -94,12 +94,6 @@ func TestCreate(t *testing.T) {
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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)
|
||||
&api.Pod{
|
||||
Spec: api.PodSpec{
|
||||
@ -113,19 +107,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, _, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
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)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestGet(validNewPod())
|
||||
}
|
||||
|
||||
func TestEtcdList(t *testing.T) {
|
||||
func TestList(t *testing.T) {
|
||||
storage, _, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
key := etcdtest.AddPrefix(storage.Etcd.KeyRootFunc(test.TestContext()))
|
||||
test.TestList(
|
||||
validNewPod(),
|
||||
func(objects []runtime.Object) []runtime.Object {
|
||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
||||
},
|
||||
func(resourceVersion uint64) {
|
||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
||||
})
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestList(validNewPod())
|
||||
}
|
||||
|
||||
func TestEtcdWatch(t *testing.T) {
|
||||
func TestWatch(t *testing.T) {
|
||||
storage, _, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestWatch(
|
||||
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
|
||||
[]labels.Set{},
|
||||
// not matching labels
|
||||
@ -431,7 +399,6 @@ func TestEtcdWatch(t *testing.T) {
|
||||
[]fields.Set{
|
||||
{"metadata.name": "bar"},
|
||||
},
|
||||
registrytest.WatchActions,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -28,13 +28,13 @@ import (
|
||||
)
|
||||
|
||||
type REST struct {
|
||||
etcdgeneric.Etcd
|
||||
*etcdgeneric.Etcd
|
||||
}
|
||||
|
||||
// NewREST returns a RESTStorage object that will work against pod templates.
|
||||
func NewREST(s storage.Interface) *REST {
|
||||
prefix := "/podtemplates"
|
||||
store := etcdgeneric.Etcd{
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.PodTemplate{} },
|
||||
NewListFunc: func() runtime.Object { return &api.PodTemplateList{} },
|
||||
KeyRootFunc: func(ctx api.Context) string {
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest/resttest"
|
||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/tools"
|
||||
@ -60,18 +59,12 @@ func validNewPodTemplate(name string) *api.PodTemplate {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
pod := validNewPodTemplate("foo")
|
||||
pod.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&api.PodTemplate{
|
||||
Template: api.PodTemplateSpec{},
|
||||
@ -81,19 +74,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestUpdate(
|
||||
//valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
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"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest/resttest"
|
||||
"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/storage"
|
||||
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
|
||||
@ -37,12 +41,166 @@ func NewEtcdStorage(t *testing.T) (storage.Interface, *tools.FakeEtcdClient) {
|
||||
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)
|
||||
type newFunc func() runtime.Object
|
||||
func New(t *testing.T, fakeClient *tools.FakeEtcdClient, storage *etcdgeneric.Etcd) *Tester {
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -54,76 +212,10 @@ func EmitObject(fakeClient *tools.FakeEtcdClient, obj runtime.Object, action str
|
||||
if action == etcdstorage.EtcdDelete {
|
||||
prevNode = node
|
||||
}
|
||||
fakeClient.WatchResponse <- &etcd.Response{
|
||||
t.fakeClient.WatchResponse <- &etcd.Response{
|
||||
Action: action,
|
||||
Node: node,
|
||||
PrevNode: prevNode,
|
||||
}
|
||||
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/resource"
|
||||
"k8s.io/kubernetes/pkg/api/rest/resttest"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"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) {
|
||||
storage, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
resourcequota := validNewResourceQuota()
|
||||
resourcequota.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&api.ResourceQuota{
|
||||
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)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestGet(validNewResourceQuota())
|
||||
}
|
||||
|
||||
func TestEtcdList(t *testing.T) {
|
||||
func TestList(t *testing.T) {
|
||||
storage, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
key := etcdtest.AddPrefix(storage.Etcd.KeyRootFunc(test.TestContext()))
|
||||
test.TestList(
|
||||
validNewResourceQuota(),
|
||||
func(objects []runtime.Object) []runtime.Object {
|
||||
return registrytest.SetObjectsForKey(fakeClient, key, objects)
|
||||
},
|
||||
func(resourceVersion uint64) {
|
||||
registrytest.SetResourceVersion(fakeClient, resourceVersion)
|
||||
})
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestList(validNewResourceQuota())
|
||||
}
|
||||
|
||||
func TestEtcdWatch(t *testing.T) {
|
||||
func TestWatch(t *testing.T) {
|
||||
storage, _, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestWatch(
|
||||
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
|
||||
[]labels.Set{},
|
||||
// not matching labels
|
||||
@ -225,7 +192,6 @@ func TestEtcdWatch(t *testing.T) {
|
||||
[]fields.Set{
|
||||
{"metadata.name": "bar"},
|
||||
},
|
||||
registrytest.WatchActions,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest/resttest"
|
||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/tools"
|
||||
@ -45,18 +44,12 @@ func validNewSecret(name string) *api.Secret {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
secret := validNewSecret("foo")
|
||||
secret.ObjectMeta = api.ObjectMeta{GenerateName: "foo-"}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&api.Secret{},
|
||||
&api.Secret{
|
||||
@ -72,19 +65,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
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 {
|
||||
etcdgeneric.Etcd
|
||||
*etcdgeneric.Etcd
|
||||
}
|
||||
|
||||
// NewREST returns a RESTStorage object that will work against services.
|
||||
func NewREST(s storage.Interface) *REST {
|
||||
prefix := "/services/specs"
|
||||
store := etcdgeneric.Etcd{
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.Service{} },
|
||||
NewListFunc: func() runtime.Object { return &api.ServiceList{} },
|
||||
KeyRootFunc: func(ctx api.Context) string {
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest/resttest"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||
@ -56,18 +55,12 @@ func validService() *api.Service {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
validService := validService()
|
||||
validService.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
validService,
|
||||
func(ctx api.Context, obj runtime.Object) error {
|
||||
return registrytest.SetObject(fakeClient, storage.KeyFunc, ctx, obj)
|
||||
},
|
||||
func(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
return registrytest.GetObject(fakeClient, storage.KeyFunc, storage.NewFunc, ctx, obj)
|
||||
},
|
||||
// invalid
|
||||
&api.Service{
|
||||
Spec: api.ServiceSpec{},
|
||||
@ -91,19 +84,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError).AllowCreateOnUpdate()
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd).AllowCreateOnUpdate()
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
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) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestWatch(
|
||||
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
|
||||
[]labels.Set{},
|
||||
// not matching labels
|
||||
@ -150,6 +137,5 @@ func TestWatch(t *testing.T) {
|
||||
[]fields.Set{
|
||||
{"metadata.name": "bar"},
|
||||
},
|
||||
registrytest.WatchActions,
|
||||
)
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest/resttest"
|
||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/tools"
|
||||
@ -43,18 +42,12 @@ func validNewServiceAccount(name string) *api.ServiceAccount {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
serviceAccount := validNewServiceAccount("foo")
|
||||
serviceAccount.ObjectMeta = api.ObjectMeta{GenerateName: "foo-"}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&api.ServiceAccount{},
|
||||
&api.ServiceAccount{
|
||||
@ -65,19 +58,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
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/testapi"
|
||||
"k8s.io/kubernetes/pkg/expapi"
|
||||
"k8s.io/kubernetes/pkg/expapi/v1"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
// Ensure that expapi/v1 package is initialized.
|
||||
_ "k8s.io/kubernetes/pkg/expapi/v1"
|
||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/tools"
|
||||
@ -34,11 +33,6 @@ import (
|
||||
"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) {
|
||||
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
|
||||
return NewREST(etcdStorage), fakeClient
|
||||
@ -60,18 +54,12 @@ func validNewThirdPartyResource(name string) *expapi.ThirdPartyResource {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
rsrc := validNewThirdPartyResource("foo")
|
||||
rsrc.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
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
|
||||
&expapi.ThirdPartyResource{},
|
||||
)
|
||||
@ -79,19 +67,10 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
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
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
object := obj.(*expapi.ThirdPartyResource)
|
||||
@ -130,73 +109,12 @@ func TestDelete(t *testing.T) {
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := resttest.New(t, storage, fakeClient.SetError)
|
||||
rsrc := 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)
|
||||
}
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestGet(validNewThirdPartyResource("foo"))
|
||||
}
|
||||
|
||||
func TestList(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{
|
||||
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])
|
||||
}
|
||||
storage, fakeClient := newStorage(t)
|
||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||
test.TestList(validNewThirdPartyResource("foo"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user