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
| func TestWebServer(t *testing.T) {
t.Parallel()
terraformOptions := &terraform.Options{
TerraformDir: "../modules/webserver",
Vars: map[string]interface{}{
"instance_type": "t3.micro",
},
}
defer terraform.Destroy(t, terraformOptions)
terraform.InitAndApply(t, terraformOptions)
publicIp := terraform.Output(t, terraformOptions, "public_ip")
// Test HTTP endpoint
url := fmt.Sprintf("http://%s", publicIp)
http_helper.HttpGetWithRetry(
t,
url,
nil,
200,
"Hello, World",
30, // retries
5*time.Second, // sleep between retries
)
// Test SSH access
host := ssh.Host{
Hostname: publicIp,
SshUserName: "ec2-user",
SshKeyPair: loadKeyPair(t),
}
output := ssh.CheckSshCommand(t, host, "cat /etc/os-release")
assert.Contains(t, output, "Amazon Linux")
}
|