-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathexamples_test.go
83 lines (71 loc) · 1.82 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
package examples
import (
"context"
"fmt"
"os"
"testing"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ecr"
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
"github.com/stretchr/testify/require"
)
func getEnvRegion(t *testing.T) string {
envRegion := os.Getenv("AWS_REGION")
if envRegion == "" {
t.Skipf("Skipping test due to missing AWS_REGION environment variable")
}
fmt.Printf("AWS Region: %v\n", envRegion)
return envRegion
}
func getCwd(t *testing.T) string {
cwd, err := os.Getwd()
if err != nil {
t.FailNow()
}
return cwd
}
func getBaseOptions(t *testing.T) integration.ProgramTestOptions {
envRegion := getEnvRegion(t)
baseJS := integration.ProgramTestOptions{
Config: map[string]string{
"aws:region": envRegion,
},
Quick: true,
SkipRefresh: true,
ExpectRefreshChanges: true,
}
return baseJS
}
func maxDuration(dur time.Duration, t *testing.T, test func(t *testing.T)) {
t.Helper()
timeout := time.After(dur)
done := make(chan bool)
go func() {
test(t)
done <- true
}()
select {
case <-timeout:
t.Fatalf("Test timed out after %v", dur)
case <-done:
}
}
func loadAwsDefaultConfig(t *testing.T) aws.Config {
loadOpts := []func(*config.LoadOptions) error{}
if p, ok := os.LookupEnv("AWS_PROFILE"); ok {
loadOpts = append(loadOpts, config.WithSharedConfigProfile(p))
}
if r, ok := os.LookupEnv("AWS_REGION"); ok {
loadOpts = append(loadOpts, config.WithRegion(r))
}
cfg, err := config.LoadDefaultConfig(context.TODO(), loadOpts...)
require.NoError(t, err, "failed to load AWS config")
return cfg
}
func createEcrClient(t *testing.T) *ecr.Client {
client := ecr.NewFromConfig(loadAwsDefaultConfig(t))
require.NotNil(t, client, "failed to create ECR client")
return client
}