@@ -440,3 +440,106 @@ func TestFlattenInstanceConfig(t *testing.T) {
440440 })
441441 }
442442}
443+
444+ // TestSelectBootConfig tests the boot configuration selection logic
445+ func TestSelectBootConfig (t * testing.T ) {
446+ tests := []struct {
447+ name string
448+ configs []InstanceConfig
449+ wantIndex int
450+ wantError bool
451+ wantErrorContains string
452+ }{
453+ {
454+ name : "Multiple configs with booted=true should error" ,
455+ configs : []InstanceConfig {
456+ {Label : "config1" , Booted : true },
457+ {Label : "config2" , Booted : true },
458+ },
459+ wantError : true ,
460+ wantErrorContains : "only one configuration profile can have 'booted' set to true" ,
461+ },
462+ {
463+ name : "Single config with booted=true should use that config" ,
464+ configs : []InstanceConfig {
465+ {Label : "config1" , Booted : false },
466+ {Label : "config2" , Booted : true },
467+ {Label : "config3" , Booted : false },
468+ },
469+ wantIndex : 1 ,
470+ wantError : false ,
471+ },
472+ {
473+ name : "No configs with booted=true should default to first config" ,
474+ configs : []InstanceConfig {
475+ {Label : "config1" , Booted : false },
476+ {Label : "config2" , Booted : false },
477+ },
478+ wantIndex : 0 ,
479+ wantError : false ,
480+ },
481+ {
482+ name : "Single config not marked as booted should use that config" ,
483+ configs : []InstanceConfig {
484+ {Label : "config1" , Booted : false },
485+ },
486+ wantIndex : 0 ,
487+ wantError : false ,
488+ },
489+ {
490+ name : "First config marked as booted should return index 0" ,
491+ configs : []InstanceConfig {
492+ {Label : "config1" , Booted : true },
493+ {Label : "config2" , Booted : false },
494+ },
495+ wantIndex : 0 ,
496+ wantError : false ,
497+ },
498+ {
499+ name : "Last config marked as booted should return its index" ,
500+ configs : []InstanceConfig {
501+ {Label : "config1" , Booted : false },
502+ {Label : "config2" , Booted : false },
503+ {Label : "config3" , Booted : true },
504+ },
505+ wantIndex : 2 ,
506+ wantError : false ,
507+ },
508+ {
509+ name : "Three configs with first one booted" ,
510+ configs : []InstanceConfig {
511+ {Label : "config1" , Booted : true },
512+ {Label : "config2" , Booted : false },
513+ {Label : "config3" , Booted : false },
514+ },
515+ wantIndex : 0 ,
516+ wantError : false ,
517+ },
518+ }
519+
520+ for _ , tt := range tests {
521+ t .Run (tt .name , func (t * testing.T ) {
522+ gotIndex , err := selectBootConfig (tt .configs )
523+
524+ if tt .wantError {
525+ if err == nil {
526+ t .Errorf ("selectBootConfig() expected error but got none" )
527+ return
528+ }
529+ if tt .wantErrorContains != "" && ! strings .Contains (err .Error (), tt .wantErrorContains ) {
530+ t .Errorf ("selectBootConfig() error = %v, want error containing %q" , err , tt .wantErrorContains )
531+ }
532+ return
533+ }
534+
535+ if err != nil {
536+ t .Errorf ("selectBootConfig() unexpected error: %v" , err )
537+ return
538+ }
539+
540+ if gotIndex != tt .wantIndex {
541+ t .Errorf ("selectBootConfig() = %d, want %d (config: %q)" , gotIndex , tt .wantIndex , tt .configs [tt .wantIndex ].Label )
542+ }
543+ })
544+ }
545+ }
0 commit comments