...
1
2
3
4
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 }
89
View as plain text