11using k8s . Models ;
22using System ;
3+ using System . Collections . Generic ;
34using Xunit ;
45using static k8s . Models . ResourceQuantity . SuffixFormat ;
56
@@ -200,7 +201,7 @@ public void QuantityString()
200201 }
201202
202203 [ Fact ]
203- public void Serialize ( )
204+ public void SerializeJson ( )
204205 {
205206 {
206207 ResourceQuantity quantity = 12000 ;
@@ -209,10 +210,25 @@ public void Serialize()
209210 }
210211
211212 [ Fact ]
212- public void DeserializeYaml ( )
213+ public void DeserializeJson ( )
213214 {
214- var value = KubernetesYaml . Deserialize < ResourceQuantity > ( "\" 1\" " ) ;
215- Assert . Equal ( new ResourceQuantity ( 1 , 0 , DecimalSI ) , value ) ;
215+ // str
216+ {
217+ var value = KubernetesJson . Deserialize < Dictionary < string , ResourceQuantity > > ( @"{""cpu"": ""1.1""}" ) ;
218+ Assert . Equal ( new ResourceQuantity ( 11 , - 1 , DecimalSI ) , value [ "cpu" ] ) ;
219+ }
220+
221+ // int
222+ {
223+ var value = KubernetesJson . Deserialize < Dictionary < string , ResourceQuantity > > ( @"{""cpu"": 1}" ) ;
224+ Assert . Equal ( new ResourceQuantity ( 1 , 0 , DecimalSI ) , value [ "cpu" ] ) ;
225+ }
226+
227+ // double
228+ {
229+ var value = KubernetesJson . Deserialize < Dictionary < string , ResourceQuantity > > ( @"{""cpu"": 1.1}" ) ;
230+ Assert . Equal ( new ResourceQuantity ( 11 , - 1 , DecimalSI ) , value [ "cpu" ] ) ;
231+ }
216232 }
217233
218234 [ Fact ]
@@ -221,5 +237,27 @@ public void SerializeYaml()
221237 var value = KubernetesYaml . Serialize ( new ResourceQuantity ( 1 , - 1 , DecimalSI ) ) ;
222238 Assert . Equal ( "100m" , value ) ;
223239 }
240+
241+ [ Fact ]
242+ public void DeserializeYaml ( )
243+ {
244+ // str
245+ {
246+ var value = KubernetesYaml . Deserialize < ResourceQuantity > ( "\" 1\" " ) ;
247+ Assert . Equal ( new ResourceQuantity ( 1 , 0 , DecimalSI ) , value ) ;
248+ }
249+
250+ // int
251+ {
252+ var value = KubernetesYaml . Deserialize < ResourceQuantity > ( "1" ) ;
253+ Assert . Equal ( new ResourceQuantity ( 1 , 0 , DecimalSI ) , value ) ;
254+ }
255+
256+ // double
257+ {
258+ var value = KubernetesYaml . Deserialize < ResourceQuantity > ( "1.1" ) ;
259+ Assert . Equal ( new ResourceQuantity ( 11 , - 1 , DecimalSI ) , value ) ;
260+ }
261+ }
224262 }
225263}
0 commit comments