(t *testing.T)
| 30 | ) |
| 31 | |
| 32 | func 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(%) |
| 57 | node1 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 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…