|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package tfe |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | +) |
| 13 | + |
| 14 | +func TestStackDeploymentRunList(t *testing.T) { |
| 15 | + skipUnlessBeta(t) |
| 16 | + |
| 17 | + client := testClient(t) |
| 18 | + ctx := context.Background() |
| 19 | + |
| 20 | + orgTest, orgTestCleanup := createOrganization(t, client) |
| 21 | + t.Cleanup(orgTestCleanup) |
| 22 | + |
| 23 | + oauthClient, cleanup := createOAuthClient(t, client, orgTest, nil) |
| 24 | + t.Cleanup(cleanup) |
| 25 | + |
| 26 | + stack, err := client.Stacks.Create(ctx, StackCreateOptions{ |
| 27 | + Name: "test-stack", |
| 28 | + VCSRepo: &StackVCSRepoOptions{ |
| 29 | + Identifier: "hashicorp-guides/pet-nulls-stack", |
| 30 | + OAuthTokenID: oauthClient.OAuthTokens[0].ID, |
| 31 | + Branch: "main", |
| 32 | + }, |
| 33 | + Project: &Project{ |
| 34 | + ID: orgTest.DefaultProject.ID, |
| 35 | + }, |
| 36 | + }) |
| 37 | + require.NoError(t, err) |
| 38 | + require.NotNil(t, stack) |
| 39 | + |
| 40 | + stackUpdated, err := client.Stacks.UpdateConfiguration(ctx, stack.ID) |
| 41 | + require.NoError(t, err) |
| 42 | + require.NotNil(t, stackUpdated) |
| 43 | + |
| 44 | + stack = pollStackDeployments(t, ctx, client, stackUpdated.ID) |
| 45 | + require.NotNil(t, stack.LatestStackConfiguration) |
| 46 | + |
| 47 | + // Get the deployment group ID from the stack configuration |
| 48 | + deploymentGroups, err := client.StackDeploymentGroups.List(ctx, stack.LatestStackConfiguration.ID, nil) |
| 49 | + require.NoError(t, err) |
| 50 | + require.NotNil(t, deploymentGroups) |
| 51 | + require.NotEmpty(t, deploymentGroups.Items) |
| 52 | + deploymentGroupID := deploymentGroups.Items[0].ID |
| 53 | + |
| 54 | + t.Run("List without options", func(t *testing.T) { |
| 55 | + t.Parallel() |
| 56 | + |
| 57 | + runList, err := client.StackDeploymentRuns.List(ctx, deploymentGroupID, nil) |
| 58 | + require.NoError(t, err) |
| 59 | + assert.NotNil(t, runList) |
| 60 | + }) |
| 61 | + |
| 62 | + t.Run("List with pagination", func(t *testing.T) { |
| 63 | + t.Parallel() |
| 64 | + |
| 65 | + runList, err := client.StackDeploymentRuns.List(ctx, deploymentGroupID, &StackDeploymentRunListOptions{ |
| 66 | + ListOptions: ListOptions{ |
| 67 | + PageNumber: 1, |
| 68 | + PageSize: 10, |
| 69 | + }, |
| 70 | + }) |
| 71 | + require.NoError(t, err) |
| 72 | + assert.NotNil(t, runList) |
| 73 | + }) |
| 74 | +} |
0 commit comments