Skip to content

Commit 281bba8

Browse files
authored
Merge pull request kubernetes#129419 from googs1025/chore/resourcequotas
chore(printers): add miss unit test for resourcequota
2 parents 87cf098 + b649c11 commit 281bba8

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

pkg/printers/internalversion/printers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,9 @@ func AddHandlers(h printers.PrintHandler) {
483483

484484
resourceQuotaColumnDefinitions := []metav1.TableColumnDefinition{
485485
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
486-
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
487486
{Name: "Request", Type: "string", Description: "Request represents a minimum amount of cpu/memory that a container may consume."},
488487
{Name: "Limit", Type: "string", Description: "Limits control the maximum amount of cpu/memory that a container may use independent of contention on the node."},
488+
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
489489
}
490490
_ = h.TableHandler(resourceQuotaColumnDefinitions, printResourceQuota)
491491
_ = h.TableHandler(resourceQuotaColumnDefinitions, printResourceQuotaList)
@@ -2792,7 +2792,7 @@ func printResourceQuota(resourceQuota *api.ResourceQuota, options printers.Gener
27922792
}
27932793

27942794
age := translateTimestampSince(resourceQuota.CreationTimestamp)
2795-
row.Cells = append(row.Cells, resourceQuota.Name, age, strings.TrimSuffix(requestColumn.String(), ", "), strings.TrimSuffix(limitColumn.String(), ", "))
2795+
row.Cells = append(row.Cells, resourceQuota.Name, strings.TrimSuffix(requestColumn.String(), ", "), strings.TrimSuffix(limitColumn.String(), ", "), age)
27962796
return []metav1.TableRow{row}, nil
27972797
}
27982798

pkg/printers/internalversion/printers_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6894,6 +6894,64 @@ func TestPrintLeaseCandidate(t *testing.T) {
68946894
}
68956895
}
68966896

6897+
func TestPrintResourceQuota(t *testing.T) {
6898+
tests := []struct {
6899+
resourceQuota api.ResourceQuota
6900+
options printers.GenerateOptions
6901+
expected []metav1.TableRow
6902+
}{
6903+
{
6904+
resourceQuota: api.ResourceQuota{
6905+
ObjectMeta: metav1.ObjectMeta{
6906+
Name: "test-resourcequota",
6907+
CreationTimestamp: metav1.Time{Time: time.Now().Add(-3e11)},
6908+
},
6909+
Spec: api.ResourceQuotaSpec{},
6910+
Status: api.ResourceQuotaStatus{
6911+
Used: api.ResourceList{
6912+
api.ResourceCPU: resource.MustParse("1"),
6913+
api.ResourceMemory: resource.MustParse("1Gi"),
6914+
api.ResourcePods: resource.MustParse("1"),
6915+
api.ResourceServices: resource.MustParse("1"),
6916+
api.ResourceReplicationControllers: resource.MustParse("1"),
6917+
api.ResourceQuotas: resource.MustParse("1"),
6918+
api.ResourceLimitsCPU: resource.MustParse("2"),
6919+
api.ResourceLimitsMemory: resource.MustParse("2Gi"),
6920+
},
6921+
Hard: api.ResourceList{
6922+
api.ResourceCPU: resource.MustParse("100"),
6923+
api.ResourceMemory: resource.MustParse("4Gi"),
6924+
api.ResourcePods: resource.MustParse("10"),
6925+
api.ResourceServices: resource.MustParse("10"),
6926+
api.ResourceReplicationControllers: resource.MustParse("10"),
6927+
api.ResourceQuotas: resource.MustParse("1"),
6928+
api.ResourceLimitsCPU: resource.MustParse("200"),
6929+
api.ResourceLimitsMemory: resource.MustParse("8Gi"),
6930+
},
6931+
},
6932+
},
6933+
expected: []metav1.TableRow{
6934+
{
6935+
Cells: []interface{}{"test-resourcequota", "cpu: 1/100, memory: 1Gi/4Gi, pods: 1/10, replicationcontrollers: 1/10, resourcequotas: 1/1, services: 1/10", "limits.cpu: 2/200, limits.memory: 2Gi/8Gi", "5m"},
6936+
},
6937+
},
6938+
},
6939+
}
6940+
6941+
for i, test := range tests {
6942+
rows, err := printResourceQuota(&test.resourceQuota, test.options)
6943+
if err != nil {
6944+
t.Fatal(err)
6945+
}
6946+
for i := range rows {
6947+
rows[i].Object.Object = nil
6948+
}
6949+
if !reflect.DeepEqual(test.expected, rows) {
6950+
t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows))
6951+
}
6952+
}
6953+
}
6954+
68976955
func TestTableRowDeepCopyShouldNotPanic(t *testing.T) {
68986956
tests := []struct {
68996957
name string

0 commit comments

Comments
 (0)