2015-01-22 21:52:40 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2015-01-22 21:52:40 +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 07:05:40 +00:00
|
|
|
package etcd
|
2015-01-22 21:52:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/api/resource"
|
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"
|
|
|
|
"k8s.io/kubernetes/pkg/tools"
|
2015-01-22 21:52:40 +00:00
|
|
|
)
|
|
|
|
|
2015-08-20 09:17:04 +00:00
|
|
|
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
|
|
|
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
|
|
|
|
return NewREST(etcdStorage), fakeClient
|
2015-01-22 21:52:40 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 14:16:39 +00:00
|
|
|
func validNewLimitRange() *api.LimitRange {
|
|
|
|
return &api.LimitRange{
|
2015-01-22 21:52:40 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
2015-08-11 07:05:40 +00:00
|
|
|
Name: "foo",
|
2015-08-20 14:16:39 +00:00
|
|
|
Namespace: api.NamespaceDefault,
|
2015-01-22 21:52:40 +00:00
|
|
|
},
|
|
|
|
Spec: api.LimitRangeSpec{
|
|
|
|
Limits: []api.LimitRangeItem{
|
|
|
|
{
|
2015-01-23 03:21:13 +00:00
|
|
|
Type: api.LimitTypePod,
|
2015-01-22 21:52:40 +00:00
|
|
|
Max: api.ResourceList{
|
|
|
|
api.ResourceCPU: resource.MustParse("100"),
|
|
|
|
api.ResourceMemory: resource.MustParse("10000"),
|
|
|
|
},
|
|
|
|
Min: api.ResourceList{
|
|
|
|
api.ResourceCPU: resource.MustParse("0"),
|
|
|
|
api.ResourceMemory: resource.MustParse("100"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-08-20 14:16:39 +00:00
|
|
|
}
|
2015-01-22 21:52:40 +00:00
|
|
|
|
2015-08-20 14:16:39 +00:00
|
|
|
func TestCreate(t *testing.T) {
|
|
|
|
storage, fakeClient := newStorage(t)
|
2015-08-31 12:11:11 +00:00
|
|
|
test := registrytest.New(t, fakeClient, storage.Etcd).GeneratesName()
|
2015-08-20 14:16:39 +00:00
|
|
|
validLimitRange := validNewLimitRange()
|
|
|
|
validLimitRange.ObjectMeta = api.ObjectMeta{}
|
|
|
|
test.TestCreate(
|
|
|
|
// valid
|
|
|
|
validLimitRange,
|
|
|
|
// invalid
|
|
|
|
&api.LimitRange{
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "_-a123-a_"},
|
2015-01-22 21:52:40 +00:00
|
|
|
},
|
2015-08-20 14:16:39 +00:00
|
|
|
)
|
2015-01-22 21:52:40 +00:00
|
|
|
}
|
2015-08-28 13:45:38 +00:00
|
|
|
|
|
|
|
func TestUpdate(t *testing.T) {
|
|
|
|
storage, fakeClient := newStorage(t)
|
2015-08-31 12:11:11 +00:00
|
|
|
test := registrytest.New(t, fakeClient, storage.Etcd).AllowCreateOnUpdate()
|
2015-08-28 13:45:38 +00:00
|
|
|
test.TestUpdate(
|
|
|
|
// valid
|
|
|
|
validNewLimitRange(),
|
|
|
|
// updateFunc
|
|
|
|
func(obj runtime.Object) runtime.Object {
|
|
|
|
object := obj.(*api.LimitRange)
|
|
|
|
object.Spec.Limits = []api.LimitRangeItem{
|
|
|
|
{
|
|
|
|
Type: api.LimitTypePod,
|
|
|
|
Max: api.ResourceList{
|
|
|
|
api.ResourceCPU: resource.MustParse("1000"),
|
|
|
|
api.ResourceMemory: resource.MustParse("100000"),
|
|
|
|
},
|
|
|
|
Min: api.ResourceList{
|
|
|
|
api.ResourceCPU: resource.MustParse("10"),
|
|
|
|
api.ResourceMemory: resource.MustParse("1000"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return object
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
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(validNewLimitRange())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestList(t *testing.T) {
|
|
|
|
storage, fakeClient := newStorage(t)
|
|
|
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
|
|
|
test.TestList(validNewLimitRange())
|
|
|
|
}
|