mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #53250 from tianshapjq/testcase-util
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. testcase to pkg/kubelet/cadvisor/util.go **What this PR does / why we need it**: testcase to pkg/kubelet/cadvisor/util.go
This commit is contained in:
commit
098cba3f14
@ -96,6 +96,7 @@ go_test(
|
||||
srcs = select({
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"cadvisor_linux_test.go",
|
||||
"util_test.go",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
@ -103,9 +104,14 @@ go_test(
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/cadvisor",
|
||||
deps = select({
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"//pkg/apis/core/v1/helper:go_default_library",
|
||||
"//pkg/features:go_default_library",
|
||||
"//pkg/kubelet/types:go_default_library",
|
||||
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
|
||||
"//vendor/github.com/google/cadvisor/metrics:go_default_library",
|
||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
|
58
pkg/kubelet/cadvisor/util_test.go
Normal file
58
pkg/kubelet/cadvisor/util_test.go
Normal file
@ -0,0 +1,58 @@
|
||||
// +build cgo,linux
|
||||
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
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 cadvisor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
info "github.com/google/cadvisor/info/v1"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCapacityFromMachineInfo(t *testing.T) {
|
||||
machineInfo := &info.MachineInfo{
|
||||
NumCores: 2,
|
||||
MemoryCapacity: 2048,
|
||||
HugePages: []info.HugePagesInfo{
|
||||
{
|
||||
PageSize: 5,
|
||||
NumPages: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// enable the features.HugePages
|
||||
utilfeature.DefaultFeatureGate.Set(fmt.Sprintf("%s=true", features.HugePages))
|
||||
|
||||
resourceList := CapacityFromMachineInfo(machineInfo)
|
||||
|
||||
// assert the cpu and memory
|
||||
assert.EqualValues(t, machineInfo.NumCores*1000, resourceList.Cpu().MilliValue(), "unexpected CPU value")
|
||||
assert.EqualValues(t, machineInfo.MemoryCapacity, resourceList.Memory().Value(), "unexpected memory value")
|
||||
|
||||
// assert the hugepage
|
||||
hugePageKey := int64(5 * 1024)
|
||||
value, found := resourceList[v1helper.HugePageResourceName(*resource.NewQuantity(hugePageKey, resource.BinarySI))]
|
||||
assert.True(t, found, "hugepage not found")
|
||||
assert.EqualValues(t, hugePageKey*10, value.Value(), "unexpected hugepage value")
|
||||
}
|
Loading…
Reference in New Issue
Block a user