@@ -133,6 +133,70 @@ func TestCreate(t *testing.T) {
133
133
}
134
134
})
135
135
136
+ t .Run ("CreateWithSpecificTemplateVersion" , func (t * testing.T ) {
137
+ t .Parallel ()
138
+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
139
+ owner := coderdtest .CreateFirstUser (t , client )
140
+ member , _ := coderdtest .CreateAnotherUser (t , client , owner .OrganizationID )
141
+ version := coderdtest .CreateTemplateVersion (t , client , owner .OrganizationID , completeWithAgent ())
142
+ coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
143
+ template := coderdtest .CreateTemplate (t , client , owner .OrganizationID , version .ID )
144
+
145
+ // Create a new version
146
+ version2 := coderdtest .CreateTemplateVersion (t , client , owner .OrganizationID , completeWithAgent (), func (ctvr * codersdk.CreateTemplateVersionRequest ) {
147
+ ctvr .TemplateID = template .ID
148
+ })
149
+ coderdtest .AwaitTemplateVersionJobCompleted (t , client , version2 .ID )
150
+
151
+ args := []string {
152
+ "create" ,
153
+ "my-workspace" ,
154
+ "--template" , template .Name ,
155
+ "--template-version" , version2 .Name ,
156
+ "--start-at" , "9:30AM Mon-Fri US/Central" ,
157
+ "--stop-after" , "8h" ,
158
+ "--automatic-updates" , "always" ,
159
+ }
160
+ inv , root := clitest .New (t , args ... )
161
+ clitest .SetupConfig (t , member , root )
162
+ doneChan := make (chan struct {})
163
+ pty := ptytest .New (t ).Attach (inv )
164
+ go func () {
165
+ defer close (doneChan )
166
+ err := inv .Run ()
167
+ assert .NoError (t , err )
168
+ }()
169
+ matches := []struct {
170
+ match string
171
+ write string
172
+ }{
173
+ {match : "compute.main" },
174
+ {match : "smith (linux, i386)" },
175
+ {match : "Confirm create" , write : "yes" },
176
+ }
177
+ for _ , m := range matches {
178
+ pty .ExpectMatch (m .match )
179
+ if len (m .write ) > 0 {
180
+ pty .WriteLine (m .write )
181
+ }
182
+ }
183
+ <- doneChan
184
+
185
+ ws , err := member .WorkspaceByOwnerAndName (context .Background (), codersdk .Me , "my-workspace" , codersdk.WorkspaceOptions {})
186
+ if assert .NoError (t , err , "expected workspace to be created" ) {
187
+ assert .Equal (t , ws .TemplateName , template .Name )
188
+ // Check if the workspace is using the new template version
189
+ assert .Equal (t , ws .LatestBuild .TemplateVersionID , version2 .ID , "expected workspace to use the specified template version" )
190
+ if assert .NotNil (t , ws .AutostartSchedule ) {
191
+ assert .Equal (t , * ws .AutostartSchedule , "CRON_TZ=US/Central 30 9 * * Mon-Fri" )
192
+ }
193
+ if assert .NotNil (t , ws .TTLMillis ) {
194
+ assert .Equal (t , * ws .TTLMillis , 8 * time .Hour .Milliseconds ())
195
+ }
196
+ assert .Equal (t , codersdk .AutomaticUpdatesAlways , ws .AutomaticUpdates )
197
+ }
198
+ })
199
+
136
200
t .Run ("InheritStopAfterFromTemplate" , func (t * testing.T ) {
137
201
t .Parallel ()
138
202
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
0 commit comments