...

Source file src/k8s.io/kubernetes/pkg/kubelet/cadvisor/util_test.go

Documentation: k8s.io/kubernetes/pkg/kubelet/cadvisor

     1  //go:build cgo && linux
     2  // +build cgo,linux
     3  
     4  /*
     5  Copyright 2017 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    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