2015-03-04 00:54:17 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2015-03-04 00:54:17 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package etcd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-09-01 13:27:13 +00:00
|
|
|
"k8s.io/kubernetes/pkg/fields"
|
|
|
|
"k8s.io/kubernetes/pkg/labels"
|
2015-08-20 09:17:04 +00:00
|
|
|
"k8s.io/kubernetes/pkg/registry/registrytest"
|
2015-08-20 14:16:39 +00:00
|
|
|
"k8s.io/kubernetes/pkg/runtime"
|
2015-10-29 09:51:32 +00:00
|
|
|
"k8s.io/kubernetes/pkg/storage"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/tools"
|
2015-03-04 00:54:17 +00:00
|
|
|
)
|
|
|
|
|
2015-08-20 09:17:04 +00:00
|
|
|
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
2015-09-04 07:06:01 +00:00
|
|
|
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
|
2015-10-29 09:51:32 +00:00
|
|
|
return NewREST(etcdStorage, storage.NoDecoration), fakeClient
|
2015-03-04 00:54:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func validNewPodTemplate(name string) *api.PodTemplate {
|
|
|
|
return &api.PodTemplate{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Namespace: api.NamespaceDefault,
|
|
|
|
},
|
2015-03-04 15:46:27 +00:00
|
|
|
Template: api.PodTemplateSpec{
|
2015-03-04 00:54:17 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: map[string]string{"test": "foo"},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
RestartPolicy: api.RestartPolicyAlways,
|
|
|
|
DNSPolicy: api.DNSClusterFirst,
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Image: "test",
|
|
|
|
ImagePullPolicy: api.PullAlways,
|
|
|
|
|
|
|
|
TerminationMessagePath: api.TerminationMessagePathDefault,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreate(t *testing.T) {
|
2015-08-20 09:17:04 +00:00
|
|
|
storage, fakeClient := newStorage(t)
|
2015-08-31 12:11:11 +00:00
|
|
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
2015-03-04 00:54:17 +00:00
|
|
|
pod := validNewPodTemplate("foo")
|
|
|
|
pod.ObjectMeta = api.ObjectMeta{}
|
|
|
|
test.TestCreate(
|
|
|
|
// valid
|
|
|
|
pod,
|
|
|
|
// invalid
|
|
|
|
&api.PodTemplate{
|
2015-03-04 15:46:27 +00:00
|
|
|
Template: api.PodTemplateSpec{},
|
2015-03-04 00:54:17 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdate(t *testing.T) {
|
2015-08-20 09:17:04 +00:00
|
|
|
storage, fakeClient := newStorage(t)
|
2015-08-31 12:11:11 +00:00
|
|
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
2015-03-04 00:54:17 +00:00
|
|
|
test.TestUpdate(
|
2015-08-28 13:45:38 +00:00
|
|
|
//valid
|
|
|
|
validNewPodTemplate("foo"),
|
|
|
|
// updateFunc
|
|
|
|
func(obj runtime.Object) runtime.Object {
|
|
|
|
object := obj.(*api.PodTemplate)
|
|
|
|
object.Template.Spec.NodeSelector = map[string]string{"a": "b"}
|
|
|
|
return object
|
|
|
|
},
|
2015-03-04 00:54:17 +00:00
|
|
|
)
|
|
|
|
}
|
2015-08-31 12:11:11 +00:00
|
|
|
|
2015-09-01 13:27:13 +00:00
|
|
|
func TestDelete(t *testing.T) {
|
|
|
|
storage, fakeClient := newStorage(t)
|
|
|
|
test := registrytest.New(t, fakeClient, storage.Etcd).ReturnDeletedObject()
|
|
|
|
test.TestDelete(validNewPodTemplate("foo"))
|
|
|
|
}
|
|
|
|
|
2015-08-31 12:11:11 +00:00
|
|
|
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"))
|
|
|
|
}
|
2015-09-01 13:27:13 +00:00
|
|
|
|
|
|
|
func TestWatch(t *testing.T) {
|
|
|
|
storage, fakeClient := newStorage(t)
|
|
|
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
|
|
|
test.TestWatch(
|
|
|
|
validNewPodTemplate("foo"),
|
|
|
|
// matching labels
|
|
|
|
[]labels.Set{},
|
|
|
|
// not matching labels
|
|
|
|
[]labels.Set{
|
|
|
|
{"foo": "bar"},
|
|
|
|
},
|
|
|
|
// matching fields
|
|
|
|
[]fields.Set{},
|
|
|
|
// not matching fields
|
|
|
|
[]fields.Set{
|
|
|
|
{"metadata.name": "bar"},
|
|
|
|
{"name": "foo"},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|