@@ -27,6 +27,7 @@ import (
27
27
"k8s.io/apimachinery/pkg/runtime/schema"
28
28
"k8s.io/apimachinery/pkg/util/diff"
29
29
"k8s.io/apimachinery/pkg/util/intstr"
30
+ "k8s.io/kubernetes/pkg/apis/apiserverinternal"
30
31
"k8s.io/kubernetes/pkg/apis/apps"
31
32
"k8s.io/kubernetes/pkg/apis/autoscaling"
32
33
"k8s.io/kubernetes/pkg/apis/batch"
@@ -5311,3 +5312,125 @@ func TestPrintPriorityLevelConfiguration(t *testing.T) {
5311
5312
}
5312
5313
}
5313
5314
}
5315
+
5316
+ func TestPrintStorageVersion (t * testing.T ) {
5317
+ commonEncodingVersion := "v1"
5318
+ tests := []struct {
5319
+ sv apiserverinternal.StorageVersion
5320
+ expected []metav1.TableRow
5321
+ }{
5322
+ {
5323
+ sv : apiserverinternal.StorageVersion {
5324
+ ObjectMeta : metav1.ObjectMeta {
5325
+ Name : "empty" ,
5326
+ CreationTimestamp : metav1.Time {Time : time .Now ().Add (1.9e9 )},
5327
+ },
5328
+ Status : apiserverinternal.StorageVersionStatus {},
5329
+ },
5330
+ // Columns: Name, CommonEncodingVersion, StorageVersions, Age
5331
+ expected : []metav1.TableRow {{Cells : []interface {}{"empty" , "<unset>" , "<unset>" , "0s" }}},
5332
+ },
5333
+ {
5334
+ sv : apiserverinternal.StorageVersion {
5335
+ ObjectMeta : metav1.ObjectMeta {
5336
+ Name : "valid" ,
5337
+ CreationTimestamp : metav1.Time {Time : time .Now ().Add (1.9e9 )},
5338
+ },
5339
+ Status : apiserverinternal.StorageVersionStatus {
5340
+ StorageVersions : []apiserverinternal.ServerStorageVersion {
5341
+ {
5342
+ APIServerID : "1" ,
5343
+ EncodingVersion : "v1" ,
5344
+ DecodableVersions : []string {"v1" },
5345
+ },
5346
+ {
5347
+ APIServerID : "2" ,
5348
+ EncodingVersion : "v1" ,
5349
+ DecodableVersions : []string {"v1" , "v2" },
5350
+ },
5351
+ },
5352
+ CommonEncodingVersion : & commonEncodingVersion ,
5353
+ },
5354
+ },
5355
+ // Columns: Name, CommonEncodingVersion, StorageVersions, Age
5356
+ expected : []metav1.TableRow {{Cells : []interface {}{"valid" , "v1" , "1=v1,2=v1" , "0s" }}},
5357
+ },
5358
+ {
5359
+ sv : apiserverinternal.StorageVersion {
5360
+ ObjectMeta : metav1.ObjectMeta {
5361
+ Name : "disagree" ,
5362
+ CreationTimestamp : metav1.Time {Time : time .Now ().Add (1.9e9 )},
5363
+ },
5364
+ Status : apiserverinternal.StorageVersionStatus {
5365
+ StorageVersions : []apiserverinternal.ServerStorageVersion {
5366
+ {
5367
+ APIServerID : "1" ,
5368
+ EncodingVersion : "v1" ,
5369
+ DecodableVersions : []string {"v1" },
5370
+ },
5371
+ {
5372
+ APIServerID : "2" ,
5373
+ EncodingVersion : "v1" ,
5374
+ DecodableVersions : []string {"v1" , "v2" },
5375
+ },
5376
+ {
5377
+ APIServerID : "3" ,
5378
+ EncodingVersion : "v2" ,
5379
+ DecodableVersions : []string {"v2" },
5380
+ },
5381
+ },
5382
+ },
5383
+ },
5384
+ // Columns: Name, CommonEncodingVersion, StorageVersions, Age
5385
+ expected : []metav1.TableRow {{Cells : []interface {}{"disagree" , "<unset>" , "1=v1,2=v1,3=v2" , "0s" }}},
5386
+ },
5387
+ {
5388
+ sv : apiserverinternal.StorageVersion {
5389
+ ObjectMeta : metav1.ObjectMeta {
5390
+ Name : "agreeWithMore" ,
5391
+ CreationTimestamp : metav1.Time {Time : time .Now ().Add (1.9e9 )},
5392
+ },
5393
+ Status : apiserverinternal.StorageVersionStatus {
5394
+ StorageVersions : []apiserverinternal.ServerStorageVersion {
5395
+ {
5396
+ APIServerID : "1" ,
5397
+ EncodingVersion : "v1" ,
5398
+ DecodableVersions : []string {"v1" },
5399
+ },
5400
+ {
5401
+ APIServerID : "2" ,
5402
+ EncodingVersion : "v1" ,
5403
+ DecodableVersions : []string {"v1" , "v2" },
5404
+ },
5405
+ {
5406
+ APIServerID : "3" ,
5407
+ EncodingVersion : "v1" ,
5408
+ DecodableVersions : []string {"v1" , "v2" },
5409
+ },
5410
+ {
5411
+ APIServerID : "4" ,
5412
+ EncodingVersion : "v1" ,
5413
+ DecodableVersions : []string {"v1" , "v2" , "v3alpha1" },
5414
+ },
5415
+ },
5416
+ CommonEncodingVersion : & commonEncodingVersion ,
5417
+ },
5418
+ },
5419
+ // Columns: Name, CommonEncodingVersion, StorageVersions, Age
5420
+ expected : []metav1.TableRow {{Cells : []interface {}{"agreeWithMore" , "v1" , "1=v1,2=v1,3=v1 + 1 more..." , "0s" }}},
5421
+ },
5422
+ }
5423
+
5424
+ for i , test := range tests {
5425
+ rows , err := printStorageVersion (& test .sv , printers.GenerateOptions {})
5426
+ if err != nil {
5427
+ t .Fatal (err )
5428
+ }
5429
+ for i := range rows {
5430
+ rows [i ].Object .Object = nil
5431
+ }
5432
+ if ! reflect .DeepEqual (test .expected , rows ) {
5433
+ t .Errorf ("%d mismatch: %s" , i , diff .ObjectReflectDiff (test .expected , rows ))
5434
+ }
5435
+ }
5436
+ }
0 commit comments