@@ -25,87 +25,57 @@ func TestPrintConditions_Process(t *testing.T) {
2525 validate func (t * testing.T , crd * apiextensions.CustomResourceDefinition )
2626 }{
2727 {
28- title : "version updated " ,
28+ title : "columns added to spec " ,
2929 apiVersion : "v1" ,
3030 versions : []apiextensions.CustomResourceDefinitionVersion {
3131 {Name : "v1beta1" , Served : true , Storage : false },
3232 {Name : "v1" , Served : true , Storage : true },
3333 },
3434 validate : func (t * testing.T , crd * apiextensions.CustomResourceDefinition ) {
35- // Find the v1 version
36- var targetVersion apiextensions.CustomResourceDefinitionVersion
37- for _ , v := range crd .Spec .Versions {
38- if v .Name == "v1" {
39- targetVersion = v
40- break
41- }
42- }
35+ // Verify columns were added at the spec level
36+ require .Len (t , crd .Spec .AdditionalPrinterColumns , 3 )
4337
44- // Verify columns were added
45- require .NotEmpty (t , targetVersion .Name , "Should have found the target version" )
46- require .Len (t , targetVersion .AdditionalPrinterColumns , 2 )
38+ assert .Equal (t , "Ready" , crd .Spec .AdditionalPrinterColumns [0 ].Name )
39+ assert .Equal (t , `.status.conditions[?(@.type=="Ready")].status` , crd .Spec .AdditionalPrinterColumns [0 ].JSONPath )
4740
48- assert .Equal (t , "Ready " , targetVersion . AdditionalPrinterColumns [0 ].Name )
49- assert .Equal (t , `.status.conditions[?(@.type=="Ready")].status ` , targetVersion . AdditionalPrinterColumns [0 ].JSONPath )
41+ assert .Equal (t , "Reason " , crd . Spec . AdditionalPrinterColumns [1 ].Name )
42+ assert .Equal (t , `.status.conditions[?(@.type=="Ready")].reason ` , crd . Spec . AdditionalPrinterColumns [1 ].JSONPath )
5043
51- assert .Equal (t , "State" , targetVersion . AdditionalPrinterColumns [1 ].Name )
52- assert .Equal (t , `.status.conditions[?(@.type=="State")].reason` , targetVersion . AdditionalPrinterColumns [1 ].JSONPath )
44+ assert .Equal (t , "State" , crd . Spec . AdditionalPrinterColumns [2 ].Name )
45+ assert .Equal (t , `.status.conditions[?(@.type=="State")].reason` , crd . Spec . AdditionalPrinterColumns [2 ].JSONPath )
5346 },
5447 },
5548 {
56- title : "missing version" ,
57- apiVersion : "v2" ,
58- versions : []apiextensions.CustomResourceDefinitionVersion {
59- {Name : "v1" , Served : true , Storage : true },
60- },
61- wantErr : "apiVersion \" v2\" not listed in spec" ,
62- validate : func (t * testing.T , crd * apiextensions.CustomResourceDefinition ) {
63- // Ensure no weird side effects happened to existing versions
64- assert .Empty (t , crd .Spec .Versions [0 ].AdditionalPrinterColumns )
65- },
66- },
67- {
68- title : "replace columns" ,
49+ title : "replace existing columns" ,
6950 apiVersion : "v1" ,
7051 versions : []apiextensions.CustomResourceDefinitionVersion {
71- {
72- Name : "v1" ,
73- AdditionalPrinterColumns : []apiextensions.CustomResourceColumnDefinition {
74- {Name : "OldColumn" , JSONPath : ".old" },
75- },
76- },
52+ {Name : "v1" , Served : true , Storage : true },
7753 },
7854 validate : func (t * testing.T , crd * apiextensions.CustomResourceDefinition ) {
79- targetVersion := crd .Spec .Versions [0 ]
80- require .Len (t , targetVersion .AdditionalPrinterColumns , 2 )
81- assert .Equal (t , "Ready" , targetVersion .AdditionalPrinterColumns [0 ].Name )
55+ require .Len (t , crd .Spec .AdditionalPrinterColumns , 3 )
56+ assert .Equal (t , "Ready" , crd .Spec .AdditionalPrinterColumns [0 ].Name )
57+ assert .Equal (t , "Reason" , crd .Spec .AdditionalPrinterColumns [1 ].Name )
58+ assert .Equal (t , "State" , crd .Spec .AdditionalPrinterColumns [2 ].Name )
8259 },
8360 },
8461 {
85- title : "unique version updated " ,
62+ title : "columns added with single version " ,
8663 apiVersion : "" ,
8764 versions : []apiextensions.CustomResourceDefinitionVersion {
8865 {Name : "v1" , Served : true , Storage : true },
8966 },
9067 validate : func (t * testing.T , crd * apiextensions.CustomResourceDefinition ) {
91- // Find the v1 version
92- var targetVersion apiextensions.CustomResourceDefinitionVersion
93- for _ , v := range crd .Spec .Versions {
94- if v .Name == "v1" {
95- targetVersion = v
96- break
97- }
98- }
68+ // Verify columns were added at the spec level
69+ require .Len (t , crd .Spec .AdditionalPrinterColumns , 3 )
9970
100- // Verify columns were added
101- require .NotEmpty (t , targetVersion .Name , "Should have found the target version" )
102- require .Len (t , targetVersion .AdditionalPrinterColumns , 2 )
71+ assert .Equal (t , "Ready" , crd .Spec .AdditionalPrinterColumns [0 ].Name )
72+ assert .Equal (t , `.status.conditions[?(@.type=="Ready")].status` , crd .Spec .AdditionalPrinterColumns [0 ].JSONPath )
10373
104- assert .Equal (t , "Ready " , targetVersion . AdditionalPrinterColumns [0 ].Name )
105- assert .Equal (t , `.status.conditions[?(@.type=="Ready")].status ` , targetVersion . AdditionalPrinterColumns [0 ].JSONPath )
74+ assert .Equal (t , "Reason " , crd . Spec . AdditionalPrinterColumns [1 ].Name )
75+ assert .Equal (t , `.status.conditions[?(@.type=="Ready")].reason ` , crd . Spec . AdditionalPrinterColumns [1 ].JSONPath )
10676
107- assert .Equal (t , "State" , targetVersion . AdditionalPrinterColumns [1 ].Name )
108- assert .Equal (t , `.status.conditions[?(@.type=="State")].reason` , targetVersion . AdditionalPrinterColumns [1 ].JSONPath )
77+ assert .Equal (t , "State" , crd . Spec . AdditionalPrinterColumns [2 ].Name )
78+ assert .Equal (t , `.status.conditions[?(@.type=="State")].reason` , crd . Spec . AdditionalPrinterColumns [2 ].JSONPath )
10979 },
11080 },
11181 }
0 commit comments