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

Function TestPrintNodeMetrics

pkg/metricsutil/metrics_printer_test.go:32–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30)
31
32func TestPrintNodeMetrics(t *testing.T) {
33
34 tests := []struct {
35 name string
36 nodeMetric []metricsapi.NodeMetrics
37 nodes []*v1.Node
38 noHeader bool
39 sortBy string
40 expectedErr error
41 expectedOutput string
42 }{
43 {
44 name: "Single node with default header",
45 nodes: []*v1.Node{newNode("node1")},
46 nodeMetric: []metricsapi.NodeMetrics{
47 {
48 ObjectMeta: metav1.ObjectMeta{Name: "node1", ResourceVersion: "10", Labels: map[string]string{"key": "value"}},
49 Window: metav1.Duration{Duration: time.Minute},
50 Usage: v1.ResourceList{
51 v1.ResourceCPU: resource.MustParse("1"),
52 v1.ResourceMemory: resource.MustParse("1Gi"),
53 },
54 },
55 },
56 expectedOutput: `NAME CPU(cores) CPU(%) MEMORY(bytes) MEMORY(%)
57node1 1000m 10% 1024Mi 10%
58`,
59 },
60 {
61 name: "Single node without header",
62 nodes: []*v1.Node{newNode("node1")},
63 nodeMetric: []metricsapi.NodeMetrics{
64 {
65 ObjectMeta: metav1.ObjectMeta{Name: "node1", ResourceVersion: "10", Labels: map[string]string{"key": "value"}},
66 Window: metav1.Duration{Duration: time.Minute},
67 Usage: v1.ResourceList{
68 v1.ResourceCPU: resource.MustParse("1"),
69 v1.ResourceMemory: resource.MustParse("1Gi"),
70 },
71 },
72 },
73 noHeader: true,
74 expectedOutput: `node1 1000m 10% 1024Mi 10%
75`,
76 },
77 {
78 name: "Multiple nodes with one missing metrics",
79 nodes: []*v1.Node{newNode("node1"), newNode("node2")},
80 nodeMetric: []metricsapi.NodeMetrics{
81 {
82 ObjectMeta: metav1.ObjectMeta{Name: "node1", ResourceVersion: "10", Labels: map[string]string{"key": "value"}},
83 Window: metav1.Duration{Duration: time.Minute},
84 Usage: v1.ResourceList{
85 v1.ResourceCPU: resource.MustParse("1"),
86 v1.ResourceMemory: resource.MustParse("1Gi"),
87 },
88 },
89 },

Callers

nothing calls this directly

Calls 5

PrintNodeMetricsMethod · 0.95
newNodeFunction · 0.85
NewTopCmdPrinterFunction · 0.85
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…