-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathexamples_test.go
115 lines (98 loc) · 2.9 KB
/
examples_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
package examples
import (
"context"
"io"
"math/rand"
"net/http"
"os"
"testing"
"time"
testreplay "github.com/pulumi/providertest/replay"
pfbridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge"
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
aws "github.com/pulumi/pulumi-aws/provider/v6"
version "github.com/pulumi/pulumi-aws/provider/v6/pkg/version"
)
func createEditDir(dir string) integration.EditDir {
return integration.EditDir{Dir: dir, ExtraRuntimeValidation: nil}
}
func skipIfShort(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}
}
func getEnvRegion(t *testing.T) string {
envRegion := os.Getenv("AWS_REGION")
if envRegion == "" {
t.Skipf("Skipping test due to missing AWS_REGION environment variable")
}
return envRegion
}
func getCwd(t *testing.T) string {
cwd, err := os.Getwd()
if err != nil {
t.FailNow()
}
return cwd
}
func validateAPITest(isValid func(body string)) func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
return func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
var resp *http.Response
var err error
url := stack.Outputs["url"].(string)
// Retry a couple times on 5xx
for i := 0; i < 5; i++ {
resp, err = http.Get(url)
if !assert.NoError(t, err) {
return
}
if resp.StatusCode < 500 {
break
}
time.Sleep(10 * time.Second)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
isValid(string(body))
}
}
func init() {
// This is necessary for gRPC testing. It doesn't effect integration tests, since
// they use their own binary.
version.Version = "6.0.0"
}
func replay(t *testing.T, sequence string) {
info := *aws.Provider()
ctx := context.Background()
p, err := pfbridge.MakeMuxedServer(ctx, info.Name, info,
/*
* We leave the schema blank. This will result in incorrect calls to
* GetSchema, but otherwise does not effect the provider. It reduces the
* time to test start by minutes.
*/
[]byte("{}"),
)(nil)
require.NoError(t, err)
testreplay.ReplaySequence(t, p, sequence)
}
var letterRunes = []rune("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func randomString(length int) string {
b := make([]rune, length)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}
// A lot of tests do not currently refresh cleanly. The work to root cause each tests has not been
// done yet but the common causes are listed here:
//
// TODO[pulumi/pulumi-aws#2246] specifically affects overlays such as bucket.onObjectCreated; may be worked around
// TODO[pulumi/pulumi#6235]
// TODO[pulumi/pulumi-terraform-bridge#1595]
func skipRefresh(opts *integration.ProgramTestOptions) {
opts.SkipRefresh = true
}