forked from jen20/riviera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.go
79 lines (66 loc) · 2.16 KB
/
runner.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
package test
import (
"fmt"
"log"
"os"
"testing"
"github.com/hashicorp/go-multierror"
"github.com/jen20/riviera/azure"
)
const TestEnvVar = "RIVIERA_TEST"
type TestCase struct {
Steps []Step
State AzureStateBag
}
func Test(t *testing.T, c TestCase) {
// We only run acceptance tests if an env var is set because they're
// slow and generally require some outside configuration.
if os.Getenv(TestEnvVar) == "" {
t.Skip(fmt.Sprintf(
"Acceptance tests skipped unless env '%s' set",
TestEnvVar))
return
}
// We require verbose mode so that the user knows what is going on.
if !testing.Verbose() {
t.Fatal("Acceptance tests must be run with the -v flag on tests")
return
}
creds := &azure.AzureResourceManagerCredentials{
ClientID: os.Getenv("ARM_CLIENT_ID"),
ClientSecret: os.Getenv("ARM_CLIENT_SECRET"),
TenantID: os.Getenv("ARM_TENANT_ID"),
SubscriptionID: os.Getenv("ARM_SUBSCRIPTION_ID"),
}
var prerollErrors *multierror.Error
if creds.ClientID == "" {
prerollErrors = multierror.Append(prerollErrors, fmt.Errorf("The ARM_CLIENT_ID environment variable must be set to run acceptance tests"))
}
if creds.ClientSecret == "" {
prerollErrors = multierror.Append(prerollErrors, fmt.Errorf("The ARM_CLIENT_SECRET environment variable must be set to run acceptance tests"))
}
if creds.TenantID == "" {
prerollErrors = multierror.Append(prerollErrors, fmt.Errorf("The ARM_TENANT_ID environment variable must be set to run acceptance tests"))
}
if creds.SubscriptionID == "" {
prerollErrors = multierror.Append(prerollErrors, fmt.Errorf("The ARM_SUBSCRIPTION_ID environment variable must be set to run acceptance tests"))
}
if errs := prerollErrors.ErrorOrNil(); errs != nil {
t.Fatal(errs)
}
log.Println("[INFO] Creating Azure Client...")
azureClient, err := azure.NewClient(creds)
if err != nil {
t.Fatalf("Error creating Azure Client: %s", err)
}
state := &basicAzureStateBag{
AzureClient: azureClient,
}
runner := &basicRunner{
Steps: c.Steps,
}
runner.Run(state)
if errs := state.ErrorsOrNil(); errs != nil {
log.Fatal(fmt.Sprintf("%s\n\nThere may be dangling resources in your Azure account!", errs))
}
}