Skip to content

Commit a4a6c3e

Browse files
testing approving all plans for deployment groups
1 parent e2cfe2a commit a4a6c3e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

stack_deployment_groups.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func (s stackDeploymentGroups) Read(ctx context.Context, stackDeploymentGroupID
102102
return sdg, nil
103103
}
104104

105+
// ApproveAllPlans approves all pending plans in a stack deployment group.
105106
func (s stackDeploymentGroups) ApproveAllPlans(ctx context.Context, stackDeploymentGroupID string) error {
106107
if !validStringID(&stackDeploymentGroupID) {
107108
return fmt.Errorf("invalid stack deployment group ID: %s", stackDeploymentGroupID)

stack_deployment_groups_integration_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,50 @@ func TestStackDeploymentGroupsRead(t *testing.T) {
124124
require.Error(t, err)
125125
})
126126
}
127+
128+
func TestStackDeploymentGroupsApproveAllPlans(t *testing.T) {
129+
skipUnlessBeta(t)
130+
131+
client := testClient(t)
132+
ctx := context.Background()
133+
134+
orgTest, orgTestCleanup := createOrganization(t, client)
135+
t.Cleanup(orgTestCleanup)
136+
137+
oauthClient, cleanup := createOAuthClient(t, client, orgTest, nil)
138+
t.Cleanup(cleanup)
139+
140+
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
141+
Name: "test-stack",
142+
VCSRepo: &StackVCSRepoOptions{
143+
Identifier: "hashicorp-guides/pet-nulls-stack",
144+
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
145+
Branch: "main",
146+
},
147+
Project: &Project{
148+
ID: orgTest.DefaultProject.ID,
149+
},
150+
})
151+
require.NoError(t, err)
152+
require.NotNil(t, stack)
153+
154+
stackUpdated, err := client.Stacks.UpdateConfiguration(ctx, stack.ID)
155+
require.NoError(t, err)
156+
require.NotNil(t, stackUpdated)
157+
158+
stack = pollStackDeployments(t, ctx, client, stackUpdated.ID)
159+
require.NotNil(t, stack.LatestStackConfiguration)
160+
161+
// Get the deployment group ID from the stack configuration
162+
deploymentGroups, err := client.StackDeploymentGroups.List(ctx, stack.LatestStackConfiguration.ID, nil)
163+
require.NoError(t, err)
164+
require.NotNil(t, deploymentGroups)
165+
require.NotEmpty(t, deploymentGroups.Items)
166+
167+
deploymentGroupID := deploymentGroups.Items[0].ID
168+
169+
t.Run("Approve all plans", func(t *testing.T) {
170+
err := client.StackDeploymentGroups.ApproveAllPlans(ctx, deploymentGroupID)
171+
require.NoError(t, err)
172+
})
173+
}

0 commit comments

Comments
 (0)