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