Merge pull request #8483 from liggitt/etcd_test

Update generic etcd tests for cluster-scoped objects
This commit is contained in:
Dawn Chen
2015-05-21 09:13:44 -07:00
7 changed files with 146 additions and 66 deletions

View File

@@ -88,9 +88,9 @@ func validChangedNode() *api.Node {
func TestCreate(t *testing.T) {
storage, fakeEtcdClient := newStorage(t)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
test := resttest.New(t, storage, fakeEtcdClient.SetError).ClusterScope()
node := validNewNode()
node.ObjectMeta = api.ObjectMeta{}
node.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
test.TestCreate(
// valid
node,
@@ -102,9 +102,9 @@ func TestCreate(t *testing.T) {
}
func TestDelete(t *testing.T) {
ctx := api.NewDefaultContext()
ctx := api.NewContext()
storage, fakeEtcdClient := newStorage(t)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
test := resttest.New(t, storage, fakeEtcdClient.SetError).ClusterScope()
node := validChangedNode()
key, _ := storage.KeyFunc(ctx, node.Name)

View File

@@ -71,15 +71,15 @@ func TestStorage(t *testing.T) {
func TestCreate(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
storage, _, _ := NewStorage(helper)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
test := resttest.New(t, storage, fakeEtcdClient.SetError).ClusterScope()
namespace := validNewNamespace()
namespace.ObjectMeta = api.ObjectMeta{}
namespace.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
test.TestCreate(
// valid
namespace,
// invalid
&api.Namespace{
ObjectMeta: api.ObjectMeta{Namespace: "nope"},
ObjectMeta: api.ObjectMeta{Name: "bad value"},
},
)
}
@@ -97,13 +97,13 @@ func TestCreateSetsFields(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
storage, _, _ := NewStorage(helper)
namespace := validNewNamespace()
_, err := storage.Create(api.NewDefaultContext(), namespace)
_, err := storage.Create(api.NewContext(), namespace)
if err != fakeEtcdClient.Err {
t.Fatalf("unexpected error: %v", err)
}
actual := &api.Namespace{}
ctx := api.NewDefaultContext()
ctx := api.NewContext()
key, err := storage.Etcd.KeyFunc(ctx, "foo")
if err != nil {
t.Fatalf("unexpected key error: %v", err)
@@ -166,7 +166,7 @@ func TestListNamespaceList(t *testing.T) {
},
}
storage, _, _ := NewStorage(helper)
namespacesObj, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
namespacesObj, err := storage.List(api.NewContext(), labels.Everything(), fields.Everything())
namespaces := namespacesObj.(*api.NamespaceList)
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -214,7 +214,7 @@ func TestListNamespaceListSelection(t *testing.T) {
},
}
storage, _, _ := NewStorage(helper)
ctx := api.NewDefaultContext()
ctx := api.NewContext()
table := []struct {
label, field string
expectedIDs util.StringSet
@@ -285,7 +285,7 @@ func TestGet(t *testing.T) {
expect := validNewNamespace()
expect.Status.Phase = api.NamespaceActive
storage, fakeEtcdClient, _ := newStorage(t)
ctx := api.NewDefaultContext()
ctx := api.NewContext()
key, err := storage.Etcd.KeyFunc(ctx, "foo")
key = etcdtest.AddPrefix(key)
if err != nil {
@@ -314,7 +314,7 @@ func TestDeleteNamespace(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
fakeEtcdClient.ChangeIndex = 1
storage, _, _ := NewStorage(helper)
ctx := api.NewDefaultContext()
ctx := api.NewContext()
key, err := storage.Etcd.KeyFunc(ctx, "foo")
key = etcdtest.AddPrefix(key)
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
@@ -331,7 +331,7 @@ func TestDeleteNamespace(t *testing.T) {
},
},
}
_, err = storage.Delete(api.NewDefaultContext(), "foo", nil)
_, err = storage.Delete(api.NewContext(), "foo", nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -362,7 +362,7 @@ func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) {
},
}
storage, _, _ := NewStorage(helper)
_, err := storage.Delete(api.NewDefaultContext(), "foo", nil)
_, err := storage.Delete(api.NewContext(), "foo", nil)
if err == nil {
t.Fatalf("expected error: %v", err)
}
@@ -392,7 +392,7 @@ func TestDeleteNamespaceWithCompleteFinalizers(t *testing.T) {
},
}
storage, _, _ := NewStorage(helper)
_, err := storage.Delete(api.NewDefaultContext(), "foo", nil)
_, err := storage.Delete(api.NewContext(), "foo", nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@@ -75,9 +75,9 @@ func validChangedPersistentVolume() *api.PersistentVolume {
func TestCreate(t *testing.T) {
storage, _, fakeEtcdClient, _ := newStorage(t)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
test := resttest.New(t, storage, fakeEtcdClient.SetError).ClusterScope()
pv := validNewPersistentVolume("foo")
pv.ObjectMeta = api.ObjectMeta{}
pv.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
test.TestCreate(
// valid
pv,
@@ -89,9 +89,9 @@ func TestCreate(t *testing.T) {
}
func TestDelete(t *testing.T) {
ctx := api.NewDefaultContext()
ctx := api.NewContext()
storage, _, fakeEtcdClient, _ := newStorage(t)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
test := resttest.New(t, storage, fakeEtcdClient.SetError).ClusterScope()
pv := validChangedPersistentVolume()
key, _ := storage.KeyFunc(ctx, pv.Name)
@@ -117,7 +117,7 @@ func TestDelete(t *testing.T) {
}
func TestEtcdListPersistentVolumes(t *testing.T) {
ctx := api.NewDefaultContext()
ctx := api.NewContext()
storage, _, fakeClient, _ := newStorage(t)
key := storage.KeyRootFunc(ctx)
key = etcdtest.AddPrefix(key)
@@ -149,7 +149,7 @@ func TestEtcdListPersistentVolumes(t *testing.T) {
}
func TestEtcdGetPersistentVolumes(t *testing.T) {
ctx := api.NewDefaultContext()
ctx := api.NewContext()
storage, _, fakeClient, _ := newStorage(t)
persistentVolume := validNewPersistentVolume("foo")
name := persistentVolume.Name
@@ -180,7 +180,7 @@ func TestEtcdGetPersistentVolumes(t *testing.T) {
}
func TestListEmptyPersistentVolumesList(t *testing.T) {
ctx := api.NewDefaultContext()
ctx := api.NewContext()
storage, _, fakeClient, _ := newStorage(t)
fakeClient.ChangeIndex = 1
key := storage.KeyRootFunc(ctx)
@@ -204,7 +204,7 @@ func TestListEmptyPersistentVolumesList(t *testing.T) {
}
func TestListPersistentVolumesList(t *testing.T) {
ctx := api.NewDefaultContext()
ctx := api.NewContext()
storage, _, fakeClient, _ := newStorage(t)
fakeClient.ChangeIndex = 1
key := storage.KeyRootFunc(ctx)
@@ -264,7 +264,7 @@ func TestPersistentVolumesDecode(t *testing.T) {
}
func TestEtcdUpdatePersistentVolumes(t *testing.T) {
ctx := api.NewDefaultContext()
ctx := api.NewContext()
storage, _, fakeClient, _ := newStorage(t)
persistentVolume := validChangedPersistentVolume()
@@ -294,7 +294,7 @@ func TestEtcdUpdatePersistentVolumes(t *testing.T) {
}
func TestDeletePersistentVolumes(t *testing.T) {
ctx := api.NewDefaultContext()
ctx := api.NewContext()
storage, _, fakeClient, _ := newStorage(t)
persistentVolume := validNewPersistentVolume("foo")
name := persistentVolume.Name
@@ -318,7 +318,7 @@ func TestDeletePersistentVolumes(t *testing.T) {
func TestEtcdUpdateStatus(t *testing.T) {
storage, statusStorage, fakeClient, helper := newStorage(t)
ctx := api.NewDefaultContext()
ctx := api.NewContext()
fakeClient.TestIndex = true
key, _ := storage.KeyFunc(ctx, "foo")

View File

@@ -80,13 +80,18 @@ func TestUpdate(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
storage := NewREST(helper)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
key := etcdtest.AddPrefix("podtemplates/default/foo")
key, err := storage.KeyFunc(test.TestContext(), "foo")
if err != nil {
t.Fatal(err)
}
key = etcdtest.AddPrefix(key)
fakeEtcdClient.ExpectNotFoundGet(key)
fakeEtcdClient.ChangeIndex = 2
pod := validNewPodTemplate("foo")
existing := validNewPodTemplate("exists")
obj, err := storage.Create(api.NewDefaultContext(), existing)
existing.Namespace = test.TestNamespace()
obj, err := storage.Create(test.TestContext(), existing)
if err != nil {
t.Fatalf("unable to create object: %v", err)
}

View File

@@ -50,8 +50,7 @@ func TestCreate(t *testing.T) {
storage := NewStorage(helper)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
secret := validNewSecret("foo")
secret.Name = ""
secret.GenerateName = "foo-"
secret.ObjectMeta = api.ObjectMeta{GenerateName: "foo-"}
test.TestCreate(
// valid
secret,
@@ -72,13 +71,18 @@ func TestUpdate(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
storage := NewStorage(helper)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
key := etcdtest.AddPrefix("secrets/default/foo")
key, err := storage.KeyFunc(test.TestContext(), "foo")
if err != nil {
t.Fatal(err)
}
key = etcdtest.AddPrefix(key)
fakeEtcdClient.ExpectNotFoundGet(key)
fakeEtcdClient.ChangeIndex = 2
secret := validNewSecret("foo")
existing := validNewSecret("exists")
obj, err := storage.Create(api.NewDefaultContext(), existing)
existing.Namespace = test.TestNamespace()
obj, err := storage.Create(test.TestContext(), existing)
if err != nil {
t.Fatalf("unable to create object: %v", err)
}

View File

@@ -48,8 +48,7 @@ func TestCreate(t *testing.T) {
storage := NewStorage(helper)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
serviceAccount := validNewServiceAccount("foo")
serviceAccount.Name = ""
serviceAccount.GenerateName = "foo-"
serviceAccount.ObjectMeta = api.ObjectMeta{GenerateName: "foo-"}
test.TestCreate(
// valid
serviceAccount,
@@ -65,13 +64,18 @@ func TestUpdate(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
storage := NewStorage(helper)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
key := etcdtest.AddPrefix("serviceaccounts/default/foo")
key, err := storage.KeyFunc(test.TestContext(), "foo")
if err != nil {
t.Fatal(err)
}
key = etcdtest.AddPrefix(key)
fakeEtcdClient.ExpectNotFoundGet(key)
fakeEtcdClient.ChangeIndex = 2
serviceAccount := validNewServiceAccount("foo")
existing := validNewServiceAccount("exists")
obj, err := storage.Create(api.NewDefaultContext(), existing)
existing.Namespace = test.TestNamespace()
obj, err := storage.Create(test.TestContext(), existing)
if err != nil {
t.Fatalf("unable to create object: %v", err)
}