@@ -21,7 +21,7 @@ import (
21
21
"testing"
22
22
23
23
dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
24
- attributes "github.com/devfile/api/v2/pkg/attributes"
24
+ "github.com/devfile/api/v2/pkg/attributes"
25
25
"github.com/google/go-cmp/cmp"
26
26
fuzz "github.com/google/gofuzz"
27
27
routev1 "github.com/openshift/api/route/v1"
@@ -458,6 +458,158 @@ func TestMergeConfigMergesStorageAccessMode(t *testing.T) {
458
458
assert .Equal (t , expectedConfig .Workspace .StorageAccessMode , actualConfig .Workspace .StorageAccessMode )
459
459
}
460
460
461
+ func TestMergeConfigMergesStorageClassName (t * testing.T ) {
462
+ nonEmptyStorageClassName := "fast-ssd"
463
+ emptyStorageClassName := ""
464
+
465
+ tests := []struct {
466
+ name string
467
+ message string
468
+ from * v1alpha1.OperatorConfiguration
469
+ to * v1alpha1.OperatorConfiguration
470
+ want * v1alpha1.OperatorConfiguration
471
+ }{
472
+ {
473
+ name : "Merges non-emptyStorageClassName StorageClassName" ,
474
+ message : "Non-emptyStorageClassName StorageClassName should overwrite to" ,
475
+ from : & v1alpha1.OperatorConfiguration {
476
+ Workspace : & v1alpha1.WorkspaceConfig {
477
+ StorageClassName : & nonEmptyStorageClassName ,
478
+ },
479
+ },
480
+ to : & v1alpha1.OperatorConfiguration {
481
+ Workspace : & v1alpha1.WorkspaceConfig {},
482
+ },
483
+ want : & v1alpha1.OperatorConfiguration {
484
+ Workspace : & v1alpha1.WorkspaceConfig {
485
+ StorageClassName : & nonEmptyStorageClassName ,
486
+ },
487
+ },
488
+ },
489
+ {
490
+ name : "Merges emptyStorageClassName StorageClassName" ,
491
+ message : "Empty StorageClassName should overwrite to" ,
492
+ from : & v1alpha1.OperatorConfiguration {
493
+ Workspace : & v1alpha1.WorkspaceConfig {
494
+ StorageClassName : & emptyStorageClassName ,
495
+ },
496
+ },
497
+ to : & v1alpha1.OperatorConfiguration {
498
+ Workspace : & v1alpha1.WorkspaceConfig {
499
+ StorageClassName : & nonEmptyStorageClassName ,
500
+ },
501
+ },
502
+ want : & v1alpha1.OperatorConfiguration {
503
+ Workspace : & v1alpha1.WorkspaceConfig {
504
+ StorageClassName : & emptyStorageClassName ,
505
+ },
506
+ },
507
+ },
508
+ {
509
+ name : "Nil from StorageClassName leaves to unchanged" ,
510
+ message : "Nil in from should not overwrite to" ,
511
+ from : & v1alpha1.OperatorConfiguration {
512
+ Workspace : & v1alpha1.WorkspaceConfig {
513
+ StorageClassName : nil ,
514
+ },
515
+ },
516
+ to : & v1alpha1.OperatorConfiguration {
517
+ Workspace : & v1alpha1.WorkspaceConfig {
518
+ StorageClassName : & nonEmptyStorageClassName ,
519
+ },
520
+ },
521
+ want : & v1alpha1.OperatorConfiguration {
522
+ Workspace : & v1alpha1.WorkspaceConfig {
523
+ StorageClassName : & nonEmptyStorageClassName ,
524
+ },
525
+ },
526
+ },
527
+ }
528
+
529
+ for _ , tt := range tests {
530
+ t .Run (tt .name , func (t * testing.T ) {
531
+ mergeConfig (tt .from , tt .to )
532
+ assert .Equal (t , tt .want .Workspace .StorageClassName , tt .to .Workspace .StorageClassName , tt .message )
533
+ })
534
+ }
535
+ }
536
+
537
+ func TestMergeConfigMergesRuntimeClassName (t * testing.T ) {
538
+ nonEmptyRuntimeClassName := "kata-runtime"
539
+ emptyRuntimeClassName := ""
540
+
541
+ tests := []struct {
542
+ name string
543
+ message string
544
+ from * v1alpha1.OperatorConfiguration
545
+ to * v1alpha1.OperatorConfiguration
546
+ want * v1alpha1.OperatorConfiguration
547
+ }{
548
+ {
549
+ name : "Merges non-emptyRuntimeClassName RuntimeClassName" ,
550
+ message : "Non-emptyRuntimeClassName RuntimeClassName should overwrite to" ,
551
+ from : & v1alpha1.OperatorConfiguration {
552
+ Workspace : & v1alpha1.WorkspaceConfig {
553
+ RuntimeClassName : & nonEmptyRuntimeClassName ,
554
+ },
555
+ },
556
+ to : & v1alpha1.OperatorConfiguration {
557
+ Workspace : & v1alpha1.WorkspaceConfig {},
558
+ },
559
+ want : & v1alpha1.OperatorConfiguration {
560
+ Workspace : & v1alpha1.WorkspaceConfig {
561
+ RuntimeClassName : & nonEmptyRuntimeClassName ,
562
+ },
563
+ },
564
+ },
565
+ {
566
+ name : "Merges emptyRuntimeClassName RuntimeClassName" ,
567
+ message : "Empty RuntimeClassName should overwrite to" ,
568
+ from : & v1alpha1.OperatorConfiguration {
569
+ Workspace : & v1alpha1.WorkspaceConfig {
570
+ RuntimeClassName : & emptyRuntimeClassName ,
571
+ },
572
+ },
573
+ to : & v1alpha1.OperatorConfiguration {
574
+ Workspace : & v1alpha1.WorkspaceConfig {
575
+ RuntimeClassName : & nonEmptyRuntimeClassName ,
576
+ },
577
+ },
578
+ want : & v1alpha1.OperatorConfiguration {
579
+ Workspace : & v1alpha1.WorkspaceConfig {
580
+ RuntimeClassName : & emptyRuntimeClassName ,
581
+ },
582
+ },
583
+ },
584
+ {
585
+ name : "Nil from RuntimeClassName leaves to unchanged" ,
586
+ message : "Nil in from should not overwrite to" ,
587
+ from : & v1alpha1.OperatorConfiguration {
588
+ Workspace : & v1alpha1.WorkspaceConfig {
589
+ RuntimeClassName : nil ,
590
+ },
591
+ },
592
+ to : & v1alpha1.OperatorConfiguration {
593
+ Workspace : & v1alpha1.WorkspaceConfig {
594
+ RuntimeClassName : & nonEmptyRuntimeClassName ,
595
+ },
596
+ },
597
+ want : & v1alpha1.OperatorConfiguration {
598
+ Workspace : & v1alpha1.WorkspaceConfig {
599
+ RuntimeClassName : & nonEmptyRuntimeClassName ,
600
+ },
601
+ },
602
+ },
603
+ }
604
+
605
+ for _ , tt := range tests {
606
+ t .Run (tt .name , func (t * testing.T ) {
607
+ mergeConfig (tt .from , tt .to )
608
+ assert .Equal (t , tt .want .Workspace .RuntimeClassName , tt .to .Workspace .RuntimeClassName , tt .message )
609
+ })
610
+ }
611
+ }
612
+
461
613
func fuzzQuantity (q * resource.Quantity , c fuzz.Continue ) {
462
614
q .Set (c .Int63n (999 ))
463
615
q .Format = resource .DecimalSI
@@ -483,11 +635,11 @@ func fuzzResourceRequirements(req *corev1.ResourceRequirements, c fuzz.Continue)
483
635
req .Requests = requests
484
636
}
485
637
486
- func fuzzStringPtr (str * string , c fuzz.Continue ) {
638
+ func fuzzStringPtr (str * * string , c fuzz.Continue ) {
487
639
randString := c .RandString ()
488
- // Only set string pointer if the generated string is not empty to avoid edge cases with
489
- // replacing empty strings with nils in sync code. This edge case has to be tested manually.
490
- if randString != "" {
491
- * str = randString
640
+ // Ensure we never assign an empty string to avoid mergeConfig skipping updates.
641
+ if randString == "" {
642
+ randString = "default-string-by-fuzz"
492
643
}
644
+ * str = & randString
493
645
}
0 commit comments