@@ -578,13 +578,15 @@ func TestUpdateValidateRichParameters(t *testing.T) {
578
578
coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
579
579
template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
580
580
581
+ // Create new workspace
581
582
inv , root := clitest .New (t , "create" , "my-workspace" , "--yes" , "--template" , template .Name , "--parameter" , fmt .Sprintf ("%s=%s" , stringParameterName , "2nd" ))
582
583
clitest .SetupConfig (t , client , root )
583
584
err := inv .Run ()
584
585
require .NoError (t , err )
585
586
586
587
// Update template
587
588
updatedTemplateParameters := []* proto.RichParameter {
589
+ // The order of rich parameter options must be maintained because `cliui.Select` automatically selects the first option during tests.
588
590
{Name : stringParameterName , Type : "string" , Mutable : true , Required : true , Options : []* proto.RichParameterOption {
589
591
{Name : "first_option" , Description : "This is first option" , Value : "1" },
590
592
{Name : "second_option" , Description : "This is second option" , Value : "2" },
@@ -602,12 +604,16 @@ func TestUpdateValidateRichParameters(t *testing.T) {
602
604
// Update the workspace
603
605
inv , root = clitest .New (t , "update" , "my-workspace" )
604
606
clitest .SetupConfig (t , client , root )
605
-
607
+ doneChan := make ( chan struct {})
606
608
pty := ptytest .New (t ).Attach (inv )
607
- clitest .Start (t , inv )
609
+ go func () {
610
+ defer close (doneChan )
611
+ err := inv .Run ()
612
+ assert .NoError (t , err )
613
+ }()
608
614
609
615
matches := []string {
610
- stringParameterName , "second_option" ,
616
+ // `cliui.Select` will automatically pick the first option
611
617
"Planning workspace..." , "" ,
612
618
}
613
619
for i := 0 ; i < len (matches ); i += 2 {
@@ -619,6 +625,8 @@ func TestUpdateValidateRichParameters(t *testing.T) {
619
625
pty .WriteLine (value )
620
626
}
621
627
}
628
+
629
+ <- doneChan
622
630
})
623
631
624
632
t .Run ("ParameterOptionDisappeared" , func (t * testing.T ) {
@@ -639,16 +647,19 @@ func TestUpdateValidateRichParameters(t *testing.T) {
639
647
coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
640
648
template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
641
649
650
+ // Create new workspace
642
651
inv , root := clitest .New (t , "create" , "my-workspace" , "--yes" , "--template" , template .Name , "--parameter" , fmt .Sprintf ("%s=%s" , stringParameterName , "2nd" ))
643
652
clitest .SetupConfig (t , client , root )
653
+ ptytest .New (t ).Attach (inv )
644
654
err := inv .Run ()
645
655
require .NoError (t , err )
646
656
647
657
// Update template - 2nd option disappeared, 4th option added
648
658
updatedTemplateParameters := []* proto.RichParameter {
659
+ // The order of rich parameter options must be maintained because `cliui.Select` automatically selects the first option during tests.
649
660
{Name : stringParameterName , Type : "string" , Mutable : true , Required : true , Options : []* proto.RichParameterOption {
650
- {Name : "First option" , Description : "This is first option" , Value : "1st" },
651
661
{Name : "Third option" , Description : "This is third option" , Value : "3rd" },
662
+ {Name : "First option" , Description : "This is first option" , Value : "1st" },
652
663
{Name : "Fourth option" , Description : "This is fourth option" , Value : "4th" },
653
664
}},
654
665
}
@@ -663,11 +674,16 @@ func TestUpdateValidateRichParameters(t *testing.T) {
663
674
// Update the workspace
664
675
inv , root = clitest .New (t , "update" , "my-workspace" )
665
676
clitest .SetupConfig (t , client , root )
677
+ doneChan := make (chan struct {})
666
678
pty := ptytest .New (t ).Attach (inv )
667
- clitest .Start (t , inv )
679
+ go func () {
680
+ defer close (doneChan )
681
+ err := inv .Run ()
682
+ assert .NoError (t , err )
683
+ }()
668
684
669
685
matches := []string {
670
- stringParameterName , "Third option" ,
686
+ // `cliui.Select` will automatically pick the first option
671
687
"Planning workspace..." , "" ,
672
688
}
673
689
for i := 0 ; i < len (matches ); i += 2 {
@@ -679,6 +695,8 @@ func TestUpdateValidateRichParameters(t *testing.T) {
679
695
pty .WriteLine (value )
680
696
}
681
697
}
698
+
699
+ <- doneChan
682
700
})
683
701
684
702
t .Run ("ImmutableRequiredParameterExists_MutableRequiredParameterAdded" , func (t * testing.T ) {
@@ -742,6 +760,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
742
760
pty .WriteLine (value )
743
761
}
744
762
}
763
+
745
764
<- doneChan
746
765
})
747
766
@@ -771,10 +790,11 @@ func TestUpdateValidateRichParameters(t *testing.T) {
771
790
// Update template: add required, immutable parameter
772
791
updatedTemplateParameters := []* proto.RichParameter {
773
792
templateParameters [0 ],
793
+ // The order of rich parameter options must be maintained because `cliui.Select` automatically selects the first option during tests.
774
794
{Name : immutableParameterName , Type : "string" , Mutable : false , Required : true , Options : []* proto.RichParameterOption {
795
+ {Name : "thi" , Description : "This is third option for immutable parameter" , Value : "III" },
775
796
{Name : "fir" , Description : "This is first option for immutable parameter" , Value : "I" },
776
797
{Name : "sec" , Description : "This is second option for immutable parameter" , Value : "II" },
777
- {Name : "thi" , Description : "This is third option for immutable parameter" , Value : "III" },
778
798
}},
779
799
}
780
800
@@ -797,7 +817,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
797
817
}()
798
818
799
819
matches := []string {
800
- immutableParameterName , "thi" ,
820
+ // `cliui.Select` will automatically pick the first option
801
821
"Planning workspace..." , "" ,
802
822
}
803
823
for i := 0 ; i < len (matches ); i += 2 {
@@ -809,6 +829,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
809
829
pty .WriteLine (value )
810
830
}
811
831
}
832
+
812
833
<- doneChan
813
834
})
814
835
}
0 commit comments