Refactoring of get etcd tests.
Refactoring of get etcd tests: introudced new generic resttest, TestGet; Converted all etcd tests to use it.
This commit is contained in:
@@ -388,33 +388,6 @@ func TestPodDecode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
expect := validNewPod()
|
||||
expect.Status.Phase = api.PodRunning
|
||||
expect.Spec.NodeName = "machine"
|
||||
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
key := etcdtest.AddPrefix("/pods/test/foo")
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
R: &etcd.Response{
|
||||
Node: &etcd.Node{
|
||||
Value: runtime.EncodeOrDie(latest.Codec, expect),
|
||||
},
|
||||
},
|
||||
}
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
|
||||
obj, err := storage.Get(api.WithNamespace(api.NewContext(), "test"), "foo")
|
||||
pod := obj.(*api.Pod)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if e, a := expect, pod; !api.Semantic.DeepEqual(e, a) {
|
||||
t.Errorf("Unexpected pod: %s", util.ObjectDiff(e, a))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: remove, this is covered by RESTTest.TestCreate
|
||||
func TestPodStorageValidatesCreate(t *testing.T) {
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
@@ -661,79 +634,12 @@ func TestDeletePod(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestEtcdGetDifferentNamespace ensures same-name pods in different namespaces do not clash
|
||||
func TestEtcdGetDifferentNamespace(t *testing.T) {
|
||||
registry, _, _, fakeClient, _ := newStorage(t)
|
||||
|
||||
ctx1 := api.NewDefaultContext()
|
||||
ctx2 := api.WithNamespace(api.NewContext(), "other")
|
||||
|
||||
key1, _ := registry.KeyFunc(ctx1, "foo")
|
||||
key2, _ := registry.KeyFunc(ctx2, "foo")
|
||||
|
||||
key1 = etcdtest.AddPrefix(key1)
|
||||
key2 = etcdtest.AddPrefix(key2)
|
||||
|
||||
fakeClient.Set(key1, runtime.EncodeOrDie(latest.Codec, &api.Pod{ObjectMeta: api.ObjectMeta{Namespace: "default", Name: "foo"}}), 0)
|
||||
fakeClient.Set(key2, runtime.EncodeOrDie(latest.Codec, &api.Pod{ObjectMeta: api.ObjectMeta{Namespace: "other", Name: "foo"}}), 0)
|
||||
|
||||
obj, err := registry.Get(ctx1, "foo")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
pod1 := obj.(*api.Pod)
|
||||
if pod1.Name != "foo" {
|
||||
t.Errorf("Unexpected pod: %#v", pod1)
|
||||
}
|
||||
if pod1.Namespace != "default" {
|
||||
t.Errorf("Unexpected pod: %#v", pod1)
|
||||
}
|
||||
|
||||
obj, err = registry.Get(ctx2, "foo")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
pod2 := obj.(*api.Pod)
|
||||
if pod2.Name != "foo" {
|
||||
t.Errorf("Unexpected pod: %#v", pod2)
|
||||
}
|
||||
if pod2.Namespace != "other" {
|
||||
t.Errorf("Unexpected pod: %#v", pod2)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestEtcdGet(t *testing.T) {
|
||||
registry, _, _, fakeClient, _ := newStorage(t)
|
||||
ctx := api.NewDefaultContext()
|
||||
key, _ := registry.KeyFunc(ctx, "foo")
|
||||
key = etcdtest.AddPrefix(key)
|
||||
fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
|
||||
obj, err := registry.Get(ctx, "foo")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
pod := obj.(*api.Pod)
|
||||
if pod.Name != "foo" {
|
||||
t.Errorf("Unexpected pod: %#v", pod)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEtcdGetNotFound(t *testing.T) {
|
||||
registry, _, _, fakeClient, _ := newStorage(t)
|
||||
ctx := api.NewDefaultContext()
|
||||
key, _ := registry.KeyFunc(ctx, "foo")
|
||||
key = etcdtest.AddPrefix(key)
|
||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||
R: &etcd.Response{
|
||||
Node: nil,
|
||||
},
|
||||
E: tools.EtcdErrorNotFound,
|
||||
}
|
||||
_, err := registry.Get(ctx, "foo")
|
||||
if !errors.IsNotFound(err) {
|
||||
t.Errorf("Unexpected error returned: %#v", err)
|
||||
}
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
pod := validNewPod()
|
||||
test.TestGet(pod)
|
||||
}
|
||||
|
||||
func TestEtcdCreate(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user