-
Notifications
You must be signed in to change notification settings - Fork 21
/
influxdb_oss_test.go
129 lines (105 loc) · 4.12 KB
/
influxdb_oss_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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package test
import (
"fmt"
"path/filepath"
"strings"
"testing"
"time"
"github.com/gruntwork-io/terratest/modules/gcp"
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
)
const EXAMPLE_DIR_INFLUXDB_OSS = "influxdb-oss"
func TestInfluxDBOSS(t *testing.T) {
t.Parallel()
// For convenience - uncomment these as well as the "os" import
// when doing local testing if you need to skip any sections.
// os.Setenv("SKIP_", "true")
//os.Setenv("SKIP_bootstrap", "true")
//os.Setenv("SKIP_build_image", "true")
//os.Setenv("SKIP_deploy", "true")
//os.Setenv("SKIP_validate", "true")
//os.Setenv("SKIP_teardown", "true")
// Keeping the testcases struct, even though we're only running a single test
var testcases = []struct {
testName string
testDir string
igOutput string
packerInfo PackerInfo
sleepDuration int
}{
{
"TestInfluxDBOSS",
EXAMPLE_DIR_INFLUXDB_OSS,
"influxdb_instance_group",
PackerInfo{
builderName: "gcp",
templatePath: "influxdb-oss/influxdb-oss.json"},
0,
},
}
for _, testCase := range testcases {
// The following is necessary to make sure testCase's values don't
// get updated due to concurrency within the scope of t.Run(..) below
testCase := testCase
t.Run(testCase.testName, func(t *testing.T) {
t.Parallel()
// This is terrible - but attempt to stagger the test cases to
// avoid a concurrency issue
time.Sleep(time.Duration(testCase.sleepDuration) * time.Second)
_examplesDir := test_structure.CopyTerraformFolderToTemp(t, "../", "examples")
exampleDir := filepath.Join(_examplesDir, testCase.testDir)
test_structure.RunTestStage(t, "bootstrap", func() {
projectId := gcp.GetGoogleProjectIDFromEnvVar(t)
region := getRandomRegion(t, projectId)
zone := gcp.GetRandomZoneForRegion(t, projectId, region)
randomId := strings.ToLower(random.UniqueId())
test_structure.SaveString(t, exampleDir, KEY_REGION, region)
test_structure.SaveString(t, exampleDir, KEY_ZONE, zone)
test_structure.SaveString(t, exampleDir, KEY_PROJECT, projectId)
test_structure.SaveString(t, exampleDir, KEY_RANDOM_ID, randomId)
})
defer test_structure.RunTestStage(t, "teardown", func() {
terraformOptions := test_structure.LoadTerraformOptions(t, exampleDir)
projectId := test_structure.LoadString(t, exampleDir, KEY_PROJECT)
terraform.Destroy(t, terraformOptions)
imageName := test_structure.LoadArtifactID(t, exampleDir)
deleteImage(t, projectId, imageName)
})
test_structure.RunTestStage(t, "build_image", func() {
region := test_structure.LoadString(t, exampleDir, KEY_REGION)
projectId := test_structure.LoadString(t, exampleDir, KEY_PROJECT)
zone := test_structure.LoadString(t, exampleDir, KEY_ZONE)
randomId := test_structure.LoadString(t, exampleDir, KEY_RANDOM_ID)
imagesDir := fmt.Sprintf("%s/machine-images", _examplesDir)
templatePath := fmt.Sprintf("%s/%s", imagesDir, testCase.packerInfo.templatePath)
imageID := buildImage(t, templatePath, testCase.packerInfo.builderName, projectId, region, zone)
test_structure.SaveArtifactID(t, exampleDir, imageID)
baseName := "influxdb-oss"
clusterName := fmt.Sprintf("%s-%s", baseName, randomId)
// The vars here cover both OSS and Enterprise distributions
terraformOptions := &terraform.Options{
// The path to where your Terraform code is located
TerraformDir: exampleDir,
Vars: map[string]interface{}{
"region": region,
"project": projectId,
"image": imageID,
"name": clusterName,
},
}
test_structure.SaveTerraformOptions(t, exampleDir, terraformOptions)
})
test_structure.RunTestStage(t, "deploy", func() {
terraformOptions := test_structure.LoadTerraformOptions(t, exampleDir)
terraform.InitAndApply(t, terraformOptions)
})
test_structure.RunTestStage(t, "validate", func() {
publicIP := getNodePublicIP(t, exampleDir, testCase.igOutput)
port := "8086"
validateInfluxdb(t, publicIP, port)
})
})
}
}