forked from hashicorp/go-tfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_source_integration_test.go
68 lines (54 loc) · 1.5 KB
/
stack_source_integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package tfe
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestStackSourceCreateUploadAndRead(t *testing.T) {
skipUnlessBeta(t)
client := testClient(t)
ctx := context.Background()
orgTest, orgTestCleanup := createOrganization(t, client)
t.Cleanup(orgTestCleanup)
oauthClient, cleanup := createOAuthClient(t, client, orgTest, nil)
t.Cleanup(cleanup)
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
Project: orgTest.DefaultProject,
Name: "test-stack",
VCSRepo: &StackVCSRepoOptions{
Identifier: "hashicorp-guides/pet-nulls-stack",
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
},
})
require.NoError(t, err)
ss, err := client.StackSources.CreateAndUpload(ctx, stack.ID, "test-fixtures/stack-source", &CreateStackSourceOptions{
SelectedDeployments: []string{"simple"},
})
require.NoError(t, err)
require.NotNil(t, ss)
require.Nil(t, ss.StackConfiguration)
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
done := make(chan struct{})
go func() {
for {
ss, err = client.StackSources.Read(ctx, ss.ID)
require.NoError(t, err)
if ss.StackConfiguration != nil {
done <- struct{}{}
return
}
time.Sleep(2 * time.Second)
}
}()
select {
case <-done:
t.Logf("Found stack source configuration %q", ss.StackConfiguration.ID)
return
case <-ctx.Done():
require.Fail(t, "timed out waiting for stack source to be processed")
}
}