MCPcopy
hub / github.com/kubernetes/kubectl / TestAddPodMetrics

Function TestAddPodMetrics

pkg/metricsutil/metrics_resource_adder_test.go:63–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestAddPodMetrics(t *testing.T) {
64 resourceAdder := initResourceAdder()
65
66 tests := []struct {
67 name string
68 cpuUsage string
69 memUsage string
70 expectedCpuUsage resource.Quantity
71 expectedMemUsage resource.Quantity
72 }{
73 {
74 name: "initial value",
75 cpuUsage: "0",
76 memUsage: "0",
77 expectedCpuUsage: getResourceQuantity(t, "0"),
78 expectedMemUsage: getResourceQuantity(t, "0"),
79 },
80 {
81 name: "add first container metric",
82 cpuUsage: "1m",
83 memUsage: "10Mi",
84 expectedCpuUsage: getResourceQuantity(t, "1m"),
85 expectedMemUsage: getResourceQuantity(t, "10Mi"),
86 },
87 {
88 name: "add second container metric",
89 cpuUsage: "5m",
90 memUsage: "25Mi",
91 expectedCpuUsage: getResourceQuantity(t, "6m"),
92 expectedMemUsage: getResourceQuantity(t, "35Mi"),
93 },
94 {
95 name: "add third container zero metric",
96 cpuUsage: "0m",
97 memUsage: "0Mi",
98 expectedCpuUsage: getResourceQuantity(t, "6m"),
99 expectedMemUsage: getResourceQuantity(t, "35Mi"),
100 },
101 }
102 for _, test := range tests {
103 t.Run(test.name, func(t *testing.T) {
104 podMetrics := metrics.PodMetrics{}
105 addContainerMetricsToPodMetrics(t, &podMetrics, test.cpuUsage, test.memUsage)
106
107 resourceAdder.AddPodMetrics(&podMetrics)
108 cpuUsage := resourceAdder.total["cpu"]
109 memUsage := resourceAdder.total["memory"]
110
111 if !test.expectedCpuUsage.Equal(cpuUsage) {
112 t.Errorf("expecting cpu usage %s but getting %s", test.expectedCpuUsage.String(), cpuUsage.String())
113 }
114 if !test.expectedMemUsage.Equal(memUsage) {
115 t.Errorf("expecting memeory usage %s but getting %s", test.expectedMemUsage.String(), memUsage.String())
116 }
117 })
118 }
119}

Callers

nothing calls this directly

Calls 6

initResourceAdderFunction · 0.85
getResourceQuantityFunction · 0.85
AddPodMetricsMethod · 0.80
StringMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…