@@ -593,12 +593,138 @@ func TestUpdateValidateRichParameters(t *testing.T) {
593593 assert .NoError (t , err )
594594 }()
595595
596+ pty .ExpectMatch ("Planning workspace..." )
597+ <- doneChan
598+ })
599+
600+ t .Run ("ParameterOptionChanged" , func (t * testing.T ) {
601+ t .Parallel ()
602+
603+ // Create template and workspace
604+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
605+ user := coderdtest .CreateFirstUser (t , client )
606+
607+ templateParameters := []* proto.RichParameter {
608+ {Name : stringParameterName , Type : "string" , Mutable : true , Required : true , Options : []* proto.RichParameterOption {
609+ {Name : "First option" , Description : "This is first option" , Value : "1st" },
610+ {Name : "Second option" , Description : "This is second option" , Value : "2nd" },
611+ {Name : "Third option" , Description : "This is third option" , Value : "3rd" },
612+ }},
613+ }
614+ version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , prepareEchoResponses (templateParameters ))
615+ coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
616+ template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
617+
618+ inv , root := clitest .New (t , "create" , "my-workspace" , "--yes" , "--template" , template .Name , "--parameter" , fmt .Sprintf ("%s=%s" , stringParameterName , "2nd" ))
619+ clitest .SetupConfig (t , client , root )
620+ err := inv .Run ()
621+ require .NoError (t , err )
622+
623+ // Update template
624+ updatedTemplateParameters := []* proto.RichParameter {
625+ {Name : stringParameterName , Type : "string" , Mutable : true , Required : true , Options : []* proto.RichParameterOption {
626+ {Name : "first_option" , Description : "This is first option" , Value : "1" },
627+ {Name : "second_option" , Description : "This is second option" , Value : "2" },
628+ {Name : "third_option" , Description : "This is third option" , Value : "3" },
629+ }},
630+ }
631+
632+ updatedVersion := coderdtest .UpdateTemplateVersion (t , client , user .OrganizationID , prepareEchoResponses (updatedTemplateParameters ), template .ID )
633+ coderdtest .AwaitTemplateVersionJob (t , client , updatedVersion .ID )
634+ err = client .UpdateActiveTemplateVersion (context .Background (), template .ID , codersdk.UpdateActiveTemplateVersion {
635+ ID : updatedVersion .ID ,
636+ })
637+ require .NoError (t , err )
638+
639+ // Update the workspace
640+ inv , root = clitest .New (t , "update" , "my-workspace" )
641+ clitest .SetupConfig (t , client , root )
642+ doneChan := make (chan struct {})
643+ pty := ptytest .New (t ).Attach (inv )
644+ go func () {
645+ defer close (doneChan )
646+ err := inv .Run ()
647+ assert .NoError (t , err )
648+ }()
649+
596650 matches := []string {
651+ stringParameterName , "second_option" ,
597652 "Planning workspace..." , "" ,
598653 }
599654 for i := 0 ; i < len (matches ); i += 2 {
600655 match := matches [i ]
656+ value := matches [i + 1 ]
601657 pty .ExpectMatch (match )
658+
659+ if value != "" {
660+ pty .WriteLine (value )
661+ }
662+ }
663+ <- doneChan
664+ })
665+
666+ t .Run ("ParameterOptionDisappeared" , func (t * testing.T ) {
667+ t .Parallel ()
668+
669+ // Create template and workspace
670+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
671+ user := coderdtest .CreateFirstUser (t , client )
672+
673+ templateParameters := []* proto.RichParameter {
674+ {Name : stringParameterName , Type : "string" , Mutable : true , Required : true , Options : []* proto.RichParameterOption {
675+ {Name : "First option" , Description : "This is first option" , Value : "1st" },
676+ {Name : "Second option" , Description : "This is second option" , Value : "2nd" },
677+ {Name : "Third option" , Description : "This is third option" , Value : "3rd" },
678+ }},
679+ }
680+ version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , prepareEchoResponses (templateParameters ))
681+ coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
682+ template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
683+
684+ inv , root := clitest .New (t , "create" , "my-workspace" , "--yes" , "--template" , template .Name , "--parameter" , fmt .Sprintf ("%s=%s" , stringParameterName , "2nd" ))
685+ clitest .SetupConfig (t , client , root )
686+ err := inv .Run ()
687+ require .NoError (t , err )
688+
689+ // Update template - 2nd option disappeared, 4th option added
690+ updatedTemplateParameters := []* proto.RichParameter {
691+ {Name : stringParameterName , Type : "string" , Mutable : true , Required : true , Options : []* proto.RichParameterOption {
692+ {Name : "First option" , Description : "This is first option" , Value : "1st" },
693+ {Name : "Third option" , Description : "This is third option" , Value : "3rd" },
694+ {Name : "Fourth option" , Description : "This is fourth option" , Value : "4th" },
695+ }},
696+ }
697+
698+ updatedVersion := coderdtest .UpdateTemplateVersion (t , client , user .OrganizationID , prepareEchoResponses (updatedTemplateParameters ), template .ID )
699+ coderdtest .AwaitTemplateVersionJob (t , client , updatedVersion .ID )
700+ err = client .UpdateActiveTemplateVersion (context .Background (), template .ID , codersdk.UpdateActiveTemplateVersion {
701+ ID : updatedVersion .ID ,
702+ })
703+ require .NoError (t , err )
704+
705+ // Update the workspace
706+ inv , root = clitest .New (t , "update" , "my-workspace" )
707+ clitest .SetupConfig (t , client , root )
708+ doneChan := make (chan struct {})
709+ pty := ptytest .New (t ).Attach (inv )
710+ go func () {
711+ defer close (doneChan )
712+ err := inv .Run ()
713+ assert .NoError (t , err )
714+ }()
715+
716+ matches := []string {
717+ stringParameterName , "Third option" ,
718+ "Planning workspace..." , "" ,
719+ }
720+ for i := 0 ; i < len (matches ); i += 2 {
721+ match := matches [i ]
722+ value := matches [i + 1 ]
723+ pty .ExpectMatch (match )
724+
725+ if value != "" {
726+ pty .WriteLine (value )
727+ }
602728 }
603729 <- doneChan
604730 })
0 commit comments