mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Small refactoring of registry pod tests.
This commit is contained in:
parent
f6b20008b3
commit
d45e41a584
@ -99,15 +99,23 @@ func TestCreate(t *testing.T) {
|
|||||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||||
pod := validNewPod()
|
pod := validNewPod()
|
||||||
pod.ObjectMeta = api.ObjectMeta{}
|
pod.ObjectMeta = api.ObjectMeta{}
|
||||||
|
// Make an invalid pod with an an incorrect label.
|
||||||
|
invalidPod := validNewPod()
|
||||||
|
invalidPod.Namespace = test.TestNamespace()
|
||||||
|
invalidPod.Labels = map[string]string{
|
||||||
|
"invalid/label/to/cause/validation/failure": "bar",
|
||||||
|
}
|
||||||
test.TestCreate(
|
test.TestCreate(
|
||||||
// valid
|
// valid
|
||||||
pod,
|
pod,
|
||||||
// invalid
|
// invalid (empty contains list)
|
||||||
&api.Pod{
|
&api.Pod{
|
||||||
Spec: api.PodSpec{
|
Spec: api.PodSpec{
|
||||||
Containers: []api.Container{},
|
Containers: []api.Container{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// invalid (invalid labels)
|
||||||
|
invalidPod,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,68 +210,6 @@ func TestPodDecode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove, this is covered by RESTTest.TestCreate
|
|
||||||
func TestPodStorageValidatesCreate(t *testing.T) {
|
|
||||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
|
||||||
fakeEtcdClient.Err = fmt.Errorf("test error")
|
|
||||||
storage := NewStorage(etcdStorage, nil).Pod
|
|
||||||
|
|
||||||
pod := validNewPod()
|
|
||||||
pod.Labels = map[string]string{
|
|
||||||
"invalid/label/to/cause/validation/failure": "bar",
|
|
||||||
}
|
|
||||||
c, err := storage.Create(api.NewDefaultContext(), pod)
|
|
||||||
if c != nil {
|
|
||||||
t.Errorf("Expected nil object")
|
|
||||||
}
|
|
||||||
if !errors.IsInvalid(err) {
|
|
||||||
t.Errorf("Expected to get an invalid resource error, got %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove, this is covered by RESTTest.TestCreate
|
|
||||||
func TestCreatePod(t *testing.T) {
|
|
||||||
_, etcdStorage := newEtcdStorage(t)
|
|
||||||
storage := NewStorage(etcdStorage, nil).Pod
|
|
||||||
ctx := api.NewDefaultContext()
|
|
||||||
key, _ := storage.Etcd.KeyFunc(ctx, "foo")
|
|
||||||
|
|
||||||
pod := validNewPod()
|
|
||||||
obj, err := storage.Create(api.NewDefaultContext(), pod)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
if obj == nil {
|
|
||||||
t.Fatalf("unexpected object: %#v", obj)
|
|
||||||
}
|
|
||||||
actual := &api.Pod{}
|
|
||||||
if err := etcdStorage.Get(key, actual, false); err != nil {
|
|
||||||
t.Fatalf("unexpected extraction error: %v", err)
|
|
||||||
}
|
|
||||||
if !api.HasObjectMetaSystemFieldValues(&actual.ObjectMeta) {
|
|
||||||
t.Errorf("Expected ObjectMeta field values were populated: %#v", actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove, this is covered by RESTTest.TestCreate
|
|
||||||
func TestCreateWithConflictingNamespace(t *testing.T) {
|
|
||||||
_, etcdStorage := newEtcdStorage(t)
|
|
||||||
storage := NewStorage(etcdStorage, nil).Pod
|
|
||||||
|
|
||||||
pod := validNewPod()
|
|
||||||
pod.Namespace = "not-default"
|
|
||||||
|
|
||||||
obj, err := storage.Create(api.NewDefaultContext(), pod)
|
|
||||||
if obj != nil {
|
|
||||||
t.Error("Expected a nil obj, but we got a value")
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("Expected an error, but we didn't get one")
|
|
||||||
} else if strings.Contains(err.Error(), "Controller.Namespace does not match the provided context") {
|
|
||||||
t.Errorf("Expected 'Pod.Namespace does not match the provided context' error, got '%v'", err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUpdateWithConflictingNamespace(t *testing.T) {
|
func TestUpdateWithConflictingNamespace(t *testing.T) {
|
||||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||||
storage := NewStorage(etcdStorage, nil).Pod
|
storage := NewStorage(etcdStorage, nil).Pod
|
||||||
|
Loading…
Reference in New Issue
Block a user