|
| 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 TestStackDeploymentGroupSummaryList(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: "aa-test-stack", |
| 28 | + VCSRepo: &StackVCSRepoOptions{ |
| 29 | + Identifier: "ctrombley/linked-stacks-demo-network", |
| 30 | + OAuthTokenID: oauthClient.OAuthTokens[0].ID, |
| 31 | + }, |
| 32 | + Project: &Project{ |
| 33 | + ID: orgTest.DefaultProject.ID, |
| 34 | + }, |
| 35 | + }) |
| 36 | + require.NoError(t, err) |
| 37 | + require.NotNil(t, stack) |
| 38 | + stack2, err := client.Stacks.Create(ctx, StackCreateOptions{ |
| 39 | + Name: "bb-test-stack", |
| 40 | + VCSRepo: &StackVCSRepoOptions{ |
| 41 | + Identifier: "ctrombley/linked-stacks-demo-network", |
| 42 | + OAuthTokenID: oauthClient.OAuthTokens[0].ID, |
| 43 | + }, |
| 44 | + Project: &Project{ |
| 45 | + ID: orgTest.DefaultProject.ID, |
| 46 | + }, |
| 47 | + }) |
| 48 | + require.NoError(t, err) |
| 49 | + require.NotNil(t, stack2) |
| 50 | + |
| 51 | + // Trigger first stack configuration with a fetch |
| 52 | + _, err = client.Stacks.FetchConfiguration(ctx, stack.ID) |
| 53 | + require.NoError(t, err) |
| 54 | + |
| 55 | + updatedStack := pollStackDeploymentGroups(t, ctx, client, stack.ID) |
| 56 | + require.NotNil(t, updatedStack.LatestStackConfiguration.ID) |
| 57 | + |
| 58 | + // Trigger second stack configuration with a fetch |
| 59 | + _, err = client.Stacks.FetchConfiguration(ctx, stack2.ID) |
| 60 | + require.NoError(t, err) |
| 61 | + |
| 62 | + updatedStack2 := pollStackDeploymentGroups(t, ctx, client, stack2.ID) |
| 63 | + require.NotNil(t, updatedStack2.LatestStackConfiguration.ID) |
| 64 | + |
| 65 | + t.Run("Successful multiple deployment group summary list", func(t *testing.T) { |
| 66 | + stackConfigSummaryList, err := client.StackDeploymentGroupSummaries.List(ctx, updatedStack2.LatestStackConfiguration.ID, nil) |
| 67 | + require.NoError(t, err) |
| 68 | + |
| 69 | + assert.Len(t, stackConfigSummaryList.Items, 2) |
| 70 | + }) |
| 71 | + |
| 72 | + t.Run("Unsuccessful list", func(t *testing.T) { |
| 73 | + _, err := client.StackDeploymentGroupSummaries.List(ctx, "", nil) |
| 74 | + require.Error(t, err) |
| 75 | + }) |
| 76 | +} |
0 commit comments