...
1
2
3
4
19
20 package cadvisor
21
22 import (
23 "reflect"
24 "strings"
25 "testing"
26
27 "github.com/google/cadvisor/container/crio"
28 info "github.com/google/cadvisor/info/v1"
29 "github.com/stretchr/testify/assert"
30 "k8s.io/api/core/v1"
31 "k8s.io/apimachinery/pkg/api/resource"
32 )
33
34 func TestCapacityFromMachineInfoWithHugePagesEnable(t *testing.T) {
35 machineInfo := &info.MachineInfo{
36 NumCores: 2,
37 MemoryCapacity: 2048,
38 HugePages: []info.HugePagesInfo{
39 {
40 PageSize: 5,
41 NumPages: 10,
42 },
43 },
44 }
45
46 expected := v1.ResourceList{
47 v1.ResourceCPU: *resource.NewMilliQuantity(int64(2000), resource.DecimalSI),
48 v1.ResourceMemory: *resource.NewQuantity(int64(2048), resource.BinarySI),
49 "hugepages-5Ki": *resource.NewQuantity(int64(51200), resource.BinarySI),
50 }
51 actual := CapacityFromMachineInfo(machineInfo)
52 if !reflect.DeepEqual(actual, expected) {
53 t.Errorf("when set hugepages true, got resource list %v, want %v", actual, expected)
54 }
55 }
56
57 func TestCrioSocket(t *testing.T) {
58 assert.True(t, strings.HasSuffix(crio.CrioSocket, CrioSocketSuffix), "CrioSocketSuffix in this package must be a suffix of the one in github.com/google/cadvisor/container/crio/client.go")
59 }
60
View as plain text