k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/kubelet/cadvisor/cadvisor_linux_test.go (about) 1 //go:build linux 2 // +build linux 3 4 /* 5 Copyright 2021 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 "fmt" 24 "testing" 25 26 "github.com/stretchr/testify/assert" 27 28 "github.com/google/cadvisor/container/crio" 29 cadvisorfs "github.com/google/cadvisor/fs" 30 ) 31 32 func TestImageFsInfoLabel(t *testing.T) { 33 testcases := []struct { 34 description string 35 runtime string 36 runtimeEndpoint string 37 expectedLabel string 38 expectedError error 39 }{{ 40 description: "LabelCrioImages should be returned", 41 runtimeEndpoint: crio.CrioSocket, 42 expectedLabel: cadvisorfs.LabelCrioImages, 43 expectedError: nil, 44 }, { 45 description: "Cannot find valid imagefs label", 46 runtimeEndpoint: "", 47 expectedLabel: "", 48 expectedError: fmt.Errorf("no imagefs label for configured runtime"), 49 }} 50 51 for _, tc := range testcases { 52 t.Run(tc.description, func(t *testing.T) { 53 infoProvider := NewImageFsInfoProvider(tc.runtimeEndpoint) 54 label, err := infoProvider.ImageFsInfoLabel() 55 assert.Equal(t, tc.expectedLabel, label) 56 assert.Equal(t, tc.expectedError, err) 57 }) 58 } 59 } 60 61 func TestContainerFsInfoLabel(t *testing.T) { 62 testcases := []struct { 63 description string 64 runtime string 65 runtimeEndpoint string 66 expectedLabel string 67 expectedError error 68 }{{ 69 description: "LabelCrioWriteableImages should be returned", 70 runtimeEndpoint: crio.CrioSocket, 71 expectedLabel: cadvisorfs.LabelCrioContainers, 72 expectedError: nil, 73 }, { 74 description: "Cannot find valid imagefs label", 75 runtimeEndpoint: "", 76 expectedLabel: "", 77 expectedError: fmt.Errorf("no containerfs label for configured runtime"), 78 }} 79 80 for _, tc := range testcases { 81 t.Run(tc.description, func(t *testing.T) { 82 infoProvider := NewImageFsInfoProvider(tc.runtimeEndpoint) 83 label, err := infoProvider.ContainerFsInfoLabel() 84 assert.Equal(t, tc.expectedLabel, label) 85 assert.Equal(t, tc.expectedError, err) 86 }) 87 } 88 }