|
| 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: "hwatkins05-hashicorp/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 | + stackUpdated.LatestStackConfiguration, _ = client.StackConfigurations.Read(ctx, stackUpdated.LatestStackConfiguration.ID) |
| 45 | + |
| 46 | + t.Run("with valid stack configuration ID", func(t *testing.T) { |
| 47 | + //t.Parallel() |
| 48 | + sdgl, err := client.StackDeploymentGroups.List(ctx, stackUpdated.LatestStackConfiguration.ID, nil) |
| 49 | + require.NoError(t, err) |
| 50 | + require.NotNil(t, sdgl) |
| 51 | + |
| 52 | + for _, item := range sdgl.Items { |
| 53 | + assert.NotNil(t, item.Id) |
| 54 | + assert.NotEmpty(t, item.Name) |
| 55 | + assert.NotEmpty(t, item.Status) |
| 56 | + assert.NotNil(t, item.CreatedAt) |
| 57 | + assert.NotNil(t, item.UpdatedAt) |
| 58 | + assert.NotEmpty(t, item.StackConfigurationId) |
| 59 | + assert.GreaterOrEqual(t, item.FailureCount, 0) |
| 60 | + } |
| 61 | + }) |
| 62 | + |
| 63 | + // t.Run("with invalid stack configuration ID", func(t *testing.T) { |
| 64 | + // //t.Parallel() |
| 65 | + // _, err := client.StackDeploymentGroups.List(ctx, "", nil) |
| 66 | + // require.Error(t, err) |
| 67 | + // }) |
| 68 | + |
| 69 | + // t.Run("List with pagination", func(t *testing.T) { |
| 70 | + // t.Parallel() |
| 71 | + // options := &StackDeploymentGroupListOptions{ |
| 72 | + // ListOptions: ListOptions{ |
| 73 | + // PageNumber: 2, |
| 74 | + // PageSize: 2, |
| 75 | + // }, |
| 76 | + // } |
| 77 | + // sdgl, err := client.StackDeploymentGroups.List(ctx, stackUpdated.LatestStackConfiguration.ID, options) |
| 78 | + // require.NoError(t, err) |
| 79 | + // require.NotNil(t, sdgl) |
| 80 | + // require.Len(t, sdgl.Items, 0) |
| 81 | + // }) |
| 82 | +} |
0 commit comments