Skip to content

Commit f376230

Browse files
author
Matthew Fisher
committed
feat(tests): add domain integration tests
1 parent 58d5c52 commit f376230

6 files changed

Lines changed: 70 additions & 10 deletions

File tree

tests/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test-full: test-style
2424
godep go test -tags integration -v -run TestAuth
2525
godep go test -tags integration -v -run TestBuilds
2626
godep go test -tags integration -v -run TestConfig
27+
godep go test -tags integration -v -run TestDomains
2728
godep go test -tags integration -v -run TestKeys
2829
godep go test -tags integration -v -run TestPerms
2930
godep go test -tags integration -v -run TestPs

tests/apps_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func appsLogsTest(t *testing.T, params *utils.DeisTestConfig) {
9494
t.Fatal(err)
9595
}
9696
utils.Execute(t, gitPushCmd, params, false, "")
97-
utils.Curl(t, params)
97+
utils.CurlApp(t, *params)
9898
utils.Execute(t, cmd, params, false, "created initial release")
9999
utils.Execute(t, cmd, params, false, "listening on 5000...")
100100
if err := utils.Chdir(".."); err != nil {
@@ -103,7 +103,7 @@ func appsLogsTest(t *testing.T, params *utils.DeisTestConfig) {
103103
}
104104

105105
func appsOpenTest(t *testing.T, params *utils.DeisTestConfig) {
106-
utils.Curl(t, params)
106+
utils.CurlApp(t, *params)
107107
}
108108

109109
func appsRunTest(t *testing.T, params *utils.DeisTestConfig) {

tests/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func configSetup(t *testing.T) *utils.DeisTestConfig {
5050
// ensure custom buildpack URLS are in order
5151
utils.Execute(t, configSetBuildpackCmd, cfg, false, "https://github.com/heroku/heroku-buildpack-go#98f37cc")
5252
utils.Execute(t, gitPushCmd, cfg, false, "")
53-
utils.CurlWithFail(t, cfg, false, "the Deis team")
53+
utils.CurlApp(t, *cfg)
5454
utils.CheckList(t, "run env --app={{.AppName}}", cfg, "DEIS_APP", false)
5555
utils.CheckList(t, "run env --app={{.AppName}}", cfg, "DEIS_RELEASE", false)
5656
if err := utils.Chdir(".."); err != nil {

tests/domain_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// +build integration
2+
3+
package tests
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/deis/deis/tests/utils"
10+
)
11+
12+
var (
13+
domainsAddCmd = "domains:add {{.AppDomain}} --app {{.AppName}}"
14+
domainsRemoveCmd = "domains:remove {{.AppDomain}} --app {{.AppName}}"
15+
)
16+
17+
func TestDomain(t *testing.T) {
18+
cfg := domainSetup(t)
19+
domainTest(t, cfg)
20+
utils.AppsDestroyTest(t, cfg)
21+
}
22+
23+
func domainSetup(t *testing.T) *utils.DeisTestConfig {
24+
cfg := utils.GetGlobalConfig()
25+
cfg.AppName = "domainsample"
26+
utils.Execute(t, authLoginCmd, cfg, false, "")
27+
utils.Execute(t, gitCloneCmd, cfg, false, "")
28+
if err := utils.Chdir(cfg.ExampleApp); err != nil {
29+
t.Fatal(err)
30+
}
31+
utils.Execute(t, appsCreateCmd, cfg, false, "")
32+
utils.Execute(t, gitPushCmd, cfg, false, "")
33+
utils.CurlApp(t, *cfg)
34+
if err := utils.Chdir(".."); err != nil {
35+
t.Fatal(err)
36+
}
37+
return cfg
38+
}
39+
40+
func domainTest(t *testing.T, cfg *utils.DeisTestConfig) {
41+
utils.Execute(t, domainsAddCmd, cfg, false, "done")
42+
// ensure both the root domain and the custom domain work
43+
utils.CurlApp(t, *cfg)
44+
utils.Curl(t, fmt.Sprintf("http://%s", cfg.AppDomain))
45+
utils.Execute(t, domainsRemoveCmd, cfg, false, "done")
46+
// only the root domain should work now
47+
utils.CurlApp(t, *cfg)
48+
// TODO (bacongobbler): add test to ensure that the custom domain fails to connect
49+
}

tests/ps_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package tests
44

55
import (
6+
"fmt"
67
"os"
78
"strings"
89
"testing"
@@ -30,7 +31,7 @@ func TestPs(t *testing.T) {
3031
time.Sleep(time.Millisecond * 7000)
3132

3233
// test for a 503 response
33-
utils.CurlWithFail(t, params, true, "503")
34+
utils.CurlWithFail(t, fmt.Sprintf("http://%s.%s", params.AppName, params.Domain), true, "503")
3435

3536
utils.AppsDestroyTest(t, params)
3637
utils.Execute(t, psScaleCmd, params, true, "404 NOT FOUND")

tests/utils/itutils.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type DeisTestConfig struct {
3131
Password string
3232
Email string
3333
ExampleApp string
34+
AppDomain string
3435
AppName string
3536
ProcessNum string
3637
ImageID string
@@ -63,6 +64,10 @@ func GetGlobalConfig() *DeisTestConfig {
6364
if exampleApp == "" {
6465
exampleApp = randomApp
6566
}
67+
appDomain := os.Getenv("DEIS_TEST_APP_DOMAIN")
68+
if appDomain == "" {
69+
appDomain = fmt.Sprintf("test.%s", domain)
70+
}
6671
var envCfg = DeisTestConfig{
6772
AuthKey: authKey,
6873
Hosts: hosts,
@@ -73,6 +78,7 @@ func GetGlobalConfig() *DeisTestConfig {
7378
Password: "asdf1234",
7479
Email: "test@test.co.nz",
7580
ExampleApp: exampleApp,
81+
AppDomain: appDomain,
7682
AppName: "sample",
7783
ProcessNum: "2",
7884
ImageID: "buildtest",
@@ -97,15 +103,18 @@ func doCurl(url string) ([]byte, error) {
97103
return body, nil
98104
}
99105

100-
// Curl connects to a Deis endpoint to see if the example app is running.
101-
func Curl(t *testing.T, params *DeisTestConfig) {
102-
CurlWithFail(t, params, false, "")
106+
// Curl connects to an endpoint to see if the endpoint is responding.
107+
func Curl(t *testing.T, url string) {
108+
CurlWithFail(t, url, false, "")
103109
}
104110

105-
// CurlWithFail connects to a Deis endpoint to see if the example app is running.
106-
func CurlWithFail(t *testing.T, params *DeisTestConfig, failFlag bool, expect string) {
107-
url := "http://" + params.AppName + "." + params.Domain
111+
// CurlApp is a convenience function to see if the example app is running.
112+
func CurlApp(t *testing.T, cfg DeisTestConfig) {
113+
CurlWithFail(t, fmt.Sprintf("http://%s.%s", cfg.AppName, cfg.Domain), false, "")
114+
}
108115

116+
// CurlWithFail connects to a Deis endpoint to see if the example app is running.
117+
func CurlWithFail(t *testing.T, url string, failFlag bool, expect string) {
109118
// FIXME: try the curl a few times
110119
for i := 0; i < 20; i++ {
111120
body, err := doCurl(url)

0 commit comments

Comments
 (0)