@@ -186,3 +186,73 @@ func TestStackDeploymentGroupsApproveAllPlans(t *testing.T) {
186
186
require .NoError (t , err )
187
187
})
188
188
}
189
+
190
+ func TestStackDeploymentGroupsRerun (t * testing.T ) {
191
+ skipUnlessBeta (t )
192
+
193
+ client := testClient (t )
194
+ ctx := context .Background ()
195
+
196
+ orgTest , orgTestCleanup := createOrganization (t , client )
197
+ t .Cleanup (orgTestCleanup )
198
+
199
+ oauthClient , cleanup := createOAuthClient (t , client , orgTest , nil )
200
+ t .Cleanup (cleanup )
201
+
202
+ stack , err := client .Stacks .Create (ctx , StackCreateOptions {
203
+ Name : "test-stack" ,
204
+ VCSRepo : & StackVCSRepoOptions {
205
+ Identifier : "hashicorp-guides/pet-nulls-stack" ,
206
+ OAuthTokenID : oauthClient .OAuthTokens [0 ].ID ,
207
+ Branch : "main" ,
208
+ },
209
+ Project : & Project {
210
+ ID : orgTest .DefaultProject .ID ,
211
+ },
212
+ })
213
+ require .NoError (t , err )
214
+ require .NotNil (t , stack )
215
+
216
+ stackUpdated , err := client .Stacks .UpdateConfiguration (ctx , stack .ID )
217
+ require .NoError (t , err )
218
+ require .NotNil (t , stackUpdated )
219
+
220
+ stack = pollStackDeployments (t , ctx , client , stackUpdated .ID )
221
+ require .NotNil (t , stack .LatestStackConfiguration )
222
+
223
+ deploymentGroups , err := client .StackDeploymentGroups .List (ctx , stack .LatestStackConfiguration .ID , nil )
224
+ require .NoError (t , err )
225
+ require .NotNil (t , deploymentGroups )
226
+ require .NotEmpty (t , deploymentGroups .Items )
227
+
228
+ deploymentGroupID := deploymentGroups .Items [0 ].ID
229
+
230
+ deploymentRuns , err := client .StackDeploymentRuns .List (ctx , deploymentGroupID , nil )
231
+ require .NoError (t , err )
232
+ require .NotNil (t , deploymentRuns )
233
+ require .NotEmpty (t , deploymentRuns .Items )
234
+
235
+ err = client .StackDeploymentGroups .ApproveAllPlans (ctx , deploymentGroupID )
236
+ require .NoError (t , err )
237
+
238
+ pollStackDeploymentRunForDeployingStatus (t , ctx , client , deploymentRuns .Items [0 ].ID )
239
+
240
+ deploymentRunIds := []string {deploymentRuns .Items [0 ].ID }
241
+ for _ , dr := range deploymentRuns .Items {
242
+ deploymentRunIds = append (deploymentRunIds , dr .ID )
243
+ }
244
+
245
+ t .Run ("No deployments specified for rerun" , func (t * testing.T ) {
246
+ err := client .StackDeploymentGroups .Rerun (ctx , deploymentGroupID , nil )
247
+ require .Error (t , err )
248
+ assert .Contains (t , err .Error (), "no deployments specified for rerun" )
249
+ })
250
+
251
+ t .Run ("Rerun with invalid ID" , func (t * testing.T ) {
252
+ err := client .StackDeploymentGroups .Rerun (ctx , "" , & StackDeploymentGroupRerunOptions {
253
+ Deployments : deploymentRunIds ,
254
+ })
255
+ require .Error (t , err )
256
+ assert .Contains (t , err .Error (), "invalid stack deployment group ID" )
257
+ })
258
+ }
0 commit comments