7
7
using KubeOps . Operator . Commands . Generators ;
8
8
using KubeOps . Operator . Entities . Extensions ;
9
9
using KubeOps . Operator . Errors ;
10
+ using KubeOps . Operator . Util ;
10
11
using KubeOps . Test . TestEntities ;
12
+ using Newtonsoft . Json ;
11
13
using Xunit ;
12
14
13
15
namespace KubeOps . Test . Operator . Entities
@@ -84,7 +86,7 @@ public void Should_Set_The_Correct_Type_And_Format_For_Types(string fieldName, s
84
86
[ InlineData ( nameof ( TestSpecEntitySpec . IntegerIReadOnlySet ) , "integer" , null ) ]
85
87
public void Should_Set_The_Correct_Array_Type ( string property , string expectedType , bool ? expectedNullable )
86
88
{
87
- var propertyName = char . ToLowerInvariant ( property [ 0 ] ) + property [ 1 .. ] ;
89
+ var propertyName = property . ToCamelCase ( ) ;
88
90
var crd = _testSpecEntity . CreateCrd ( ) ;
89
91
var specProperties = crd . Spec . Versions . First ( ) . Schema . OpenAPIV3Schema . Properties [ "spec" ] ;
90
92
@@ -105,7 +107,7 @@ public void Should_Set_The_Correct_Array_Type(string property, string expectedTy
105
107
[ InlineData ( nameof ( TestSpecEntitySpec . ComplexItemsDerivedList ) ) ]
106
108
public void Should_Set_The_Correct_Complex_Array_Type ( string property )
107
109
{
108
- var propertyName = char . ToLowerInvariant ( property [ 0 ] ) + property [ 1 .. ] ;
110
+ var propertyName = property . ToCamelCase ( ) ;
109
111
var crd = _testSpecEntity . CreateCrd ( ) ;
110
112
var specProperties = crd . Spec . Versions . First ( ) . Schema . OpenAPIV3Schema . Properties [ "spec" ] ;
111
113
@@ -352,13 +354,18 @@ public void Should_Throw_On_Not_Supported_Type()
352
354
}
353
355
354
356
[ Fact ]
355
- public void Should_Add_GenericAdditionalPrinterColumns ( )
357
+ public void Should_Use_PropertyName_From_JsonPropertyAttribute ( )
356
358
{
357
359
var crd = _testSpecEntity . CreateCrd ( ) ;
358
- var apc = crd . Spec . Versions . First ( ) . AdditionalPrinterColumns ;
359
360
360
- apc . Should ( ) . NotBeNull ( ) ;
361
- apc . Should ( ) . ContainSingle ( def => def . JsonPath == ".metadata.creationTimestamp" && def . Name == "Age" ) ;
361
+ var specProperties = crd . Spec . Versions . First ( ) . Schema . OpenAPIV3Schema . Properties [ "spec" ] ;
362
+ var propertyNameFromType = nameof ( TestSpecEntitySpec . PropertyWithJsonAttribute ) ;
363
+ var propertyNameFromAttribute = typeof ( TestSpecEntitySpec )
364
+ . GetProperty ( propertyNameFromType )
365
+ ? . GetCustomAttribute < JsonPropertyAttribute > ( )
366
+ ? . PropertyName ;
367
+ specProperties . Properties . Should ( ) . ContainKey ( propertyNameFromAttribute ? . ToCamelCase ( ) ) ;
368
+ specProperties . Properties . Should ( ) . NotContainKey ( propertyNameFromType . ToCamelCase ( ) ) ;
362
369
}
363
370
364
371
[ Fact ]
@@ -383,5 +390,15 @@ public void Must_Not_Contain_Ignored_TopLevel_Properties()
383
390
var specProperties = crd . Spec . Versions . First ( ) . Schema . OpenAPIV3Schema . Properties ;
384
391
specProperties . Should ( ) . NotContainKeys ( "metadata" , "apiVersion" , "kind" ) ;
385
392
}
393
+
394
+ [ Fact ]
395
+ public void Should_Add_GenericAdditionalPrinterColumns ( )
396
+ {
397
+ var crd = _testSpecEntity . CreateCrd ( ) ;
398
+ var apc = crd . Spec . Versions . First ( ) . AdditionalPrinterColumns ;
399
+
400
+ apc . Should ( ) . NotBeNull ( ) ;
401
+ apc . Should ( ) . ContainSingle ( def => def . JsonPath == ".metadata.creationTimestamp" && def . Name == "Age" ) ;
402
+ }
386
403
}
387
404
}
0 commit comments