2015-01-25 04:19:36 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
2015-01-25 04:19:36 +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 api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/resource"
|
2015-01-25 04:19:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestResourceHelpers(t *testing.T) {
|
|
|
|
cpuLimit := resource.MustParse("10")
|
|
|
|
memoryLimit := resource.MustParse("10G")
|
2015-02-09 22:44:32 +00:00
|
|
|
resourceSpec := ResourceRequirements{
|
2015-01-25 04:19:36 +00:00
|
|
|
Limits: ResourceList{
|
|
|
|
"cpu": cpuLimit,
|
|
|
|
"memory": memoryLimit,
|
|
|
|
"kube.io/storage": memoryLimit,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if res := resourceSpec.Limits.Cpu(); *res != cpuLimit {
|
2015-08-08 01:52:23 +00:00
|
|
|
t.Errorf("expected cpulimit %v, got %v", cpuLimit, res)
|
2015-01-25 04:19:36 +00:00
|
|
|
}
|
|
|
|
if res := resourceSpec.Limits.Memory(); *res != memoryLimit {
|
2015-08-08 01:52:23 +00:00
|
|
|
t.Errorf("expected memorylimit %v, got %v", memoryLimit, res)
|
2015-01-25 04:19:36 +00:00
|
|
|
}
|
2015-02-09 22:44:32 +00:00
|
|
|
resourceSpec = ResourceRequirements{
|
2015-01-25 04:19:36 +00:00
|
|
|
Limits: ResourceList{
|
|
|
|
"memory": memoryLimit,
|
|
|
|
"kube.io/storage": memoryLimit,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if res := resourceSpec.Limits.Cpu(); res.Value() != 0 {
|
2015-08-08 01:52:23 +00:00
|
|
|
t.Errorf("expected cpulimit %v, got %v", 0, res)
|
2015-01-25 04:19:36 +00:00
|
|
|
}
|
|
|
|
if res := resourceSpec.Limits.Memory(); *res != memoryLimit {
|
2015-08-08 01:52:23 +00:00
|
|
|
t.Errorf("expected memorylimit %v, got %v", memoryLimit, res)
|
2015-01-25 04:19:36 +00:00
|
|
|
}
|
|
|
|
}
|