2014-10-09 22:21:44 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-10-09 22:21:44 +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.
|
|
|
|
*/
|
|
|
|
|
2015-08-11 09:21:00 +00:00
|
|
|
package etcd
|
2014-10-09 22:21:44 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-11-05 15:04:42 +00:00
|
|
|
"k8s.io/kubernetes/pkg/registry/generic"
|
2015-08-20 09:17:04 +00:00
|
|
|
"k8s.io/kubernetes/pkg/registry/registrytest"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/runtime"
|
2015-11-03 19:43:27 +00:00
|
|
|
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
|
2014-10-09 22:21:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var testTTL uint64 = 60
|
|
|
|
|
2015-11-03 19:43:27 +00:00
|
|
|
func newStorage(t *testing.T) (*REST, *etcdtesting.EtcdTestServer) {
|
|
|
|
etcdStorage, server := registrytest.NewEtcdStorage(t, "")
|
|
|
|
return NewREST(etcdStorage, generic.UndecoratedStorage, testTTL), server
|
2014-10-09 22:21:44 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 13:27:01 +00:00
|
|
|
func validNewEvent(namespace string) *api.Event {
|
|
|
|
return &api.Event{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Namespace: namespace,
|
2014-10-09 22:21:44 +00:00
|
|
|
},
|
2015-09-03 13:27:01 +00:00
|
|
|
Reason: "forTesting",
|
|
|
|
InvolvedObject: api.ObjectReference{
|
|
|
|
Name: "bar",
|
|
|
|
Namespace: namespace,
|
2014-10-09 22:21:44 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2015-02-05 08:05:36 +00:00
|
|
|
|
2015-09-03 13:27:01 +00:00
|
|
|
func TestCreate(t *testing.T) {
|
2015-11-03 19:43:27 +00:00
|
|
|
storage, server := newStorage(t)
|
|
|
|
defer server.Terminate(t)
|
|
|
|
test := registrytest.New(t, storage.Etcd)
|
2015-09-03 13:27:01 +00:00
|
|
|
event := validNewEvent(test.TestNamespace())
|
|
|
|
event.ObjectMeta = api.ObjectMeta{}
|
|
|
|
test.TestCreate(
|
|
|
|
// valid
|
|
|
|
event,
|
|
|
|
// invalid
|
|
|
|
&api.Event{},
|
|
|
|
)
|
|
|
|
}
|
2015-02-05 08:05:36 +00:00
|
|
|
|
2015-09-03 13:27:01 +00:00
|
|
|
func TestUpdate(t *testing.T) {
|
2015-11-03 19:43:27 +00:00
|
|
|
storage, server := newStorage(t)
|
|
|
|
defer server.Terminate(t)
|
|
|
|
test := registrytest.New(t, storage.Etcd).AllowCreateOnUpdate()
|
2015-09-03 13:27:01 +00:00
|
|
|
test.TestUpdate(
|
|
|
|
// valid
|
|
|
|
validNewEvent(test.TestNamespace()),
|
|
|
|
// valid updateFunc
|
|
|
|
func(obj runtime.Object) runtime.Object {
|
|
|
|
object := obj.(*api.Event)
|
|
|
|
object.Reason = "forDifferentTesting"
|
|
|
|
return object
|
2015-02-05 08:05:36 +00:00
|
|
|
},
|
2015-09-03 13:27:01 +00:00
|
|
|
// invalid updateFunc
|
|
|
|
func(obj runtime.Object) runtime.Object {
|
|
|
|
object := obj.(*api.Event)
|
|
|
|
object.InvolvedObject.Namespace = "different-namespace"
|
|
|
|
return object
|
2015-02-05 08:05:36 +00:00
|
|
|
},
|
2015-09-03 13:27:01 +00:00
|
|
|
)
|
|
|
|
}
|
2015-08-11 09:21:00 +00:00
|
|
|
|
2015-09-03 13:27:01 +00:00
|
|
|
func TestDelete(t *testing.T) {
|
2015-11-03 19:43:27 +00:00
|
|
|
storage, server := newStorage(t)
|
|
|
|
defer server.Terminate(t)
|
|
|
|
test := registrytest.New(t, storage.Etcd)
|
2015-09-03 13:27:01 +00:00
|
|
|
test.TestDelete(validNewEvent(test.TestNamespace()))
|
2015-02-05 08:05:36 +00:00
|
|
|
}
|