util_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // +build cgo,linux
  2. /*
  3. Copyright 2017 The Kubernetes Authors.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package cadvisor
  15. import (
  16. "reflect"
  17. "testing"
  18. "github.com/google/cadvisor/container/crio"
  19. info "github.com/google/cadvisor/info/v1"
  20. "github.com/stretchr/testify/assert"
  21. "k8s.io/api/core/v1"
  22. "k8s.io/apimachinery/pkg/api/resource"
  23. )
  24. func TestCapacityFromMachineInfoWithHugePagesEnable(t *testing.T) {
  25. machineInfo := &info.MachineInfo{
  26. NumCores: 2,
  27. MemoryCapacity: 2048,
  28. HugePages: []info.HugePagesInfo{
  29. {
  30. PageSize: 5,
  31. NumPages: 10,
  32. },
  33. },
  34. }
  35. expected := v1.ResourceList{
  36. v1.ResourceCPU: *resource.NewMilliQuantity(int64(2000), resource.DecimalSI),
  37. v1.ResourceMemory: *resource.NewQuantity(int64(2048), resource.BinarySI),
  38. "hugepages-5Ki": *resource.NewQuantity(int64(51200), resource.BinarySI),
  39. }
  40. actual := CapacityFromMachineInfo(machineInfo)
  41. if !reflect.DeepEqual(actual, expected) {
  42. t.Errorf("when set hugepages true, got resource list %v, want %v", actual, expected)
  43. }
  44. }
  45. func TestCrioSocket(t *testing.T) {
  46. assert.EqualValues(t, CrioSocket, crio.CrioSocket, "CrioSocket in this package must equal the one in github.com/google/cadvisor/container/crio/client.go")
  47. }