Skip to content

Commit ad46d77

Browse files
committed
refactor(tests): update test expectations and get suite passing
1 parent b071e08 commit ad46d77

10 files changed

Lines changed: 37 additions & 64 deletions

File tree

tests/apps_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package tests
44

55
import (
66
"testing"
7+
"time"
78

89
"github.com/deis/deis/tests/integration-utils"
910
"github.com/deis/deis/tests/utils"
@@ -12,7 +13,6 @@ import (
1213
func appsSetup(t *testing.T) *itutils.DeisTestConfig {
1314
cfg := itutils.GetGlobalConfig()
1415
cfg.AppName = "appssample"
15-
cfg.ExampleApp = itutils.GetRandomApp()
1616
cmd := itutils.GetCommand("auth", "login")
1717
itutils.Execute(t, cmd, cfg, false, "")
1818
cmd = itutils.GetCommand("git", "clone")
@@ -26,7 +26,7 @@ func appsCreateTest(t *testing.T, params *itutils.DeisTestConfig) {
2626
t.Fatalf("Failed:\n%v", err)
2727
}
2828
itutils.Execute(t, cmd, params, false, "")
29-
itutils.Execute(t, cmd, params, true, "Deis remote already exists")
29+
itutils.Execute(t, cmd, params, true, "App with this Id already exists")
3030

3131
if err := utils.Chdir(".."); err != nil {
3232
t.Fatalf("Failed:\n%v", err)
@@ -43,7 +43,7 @@ func appsRunTest(t *testing.T, params *itutils.DeisTestConfig) {
4343
if err := utils.Chdir(".."); err != nil {
4444
t.Fatalf("Failed:\n%v", err)
4545
}
46-
itutils.Execute(t, cmd, params, true, "Could not find deis remote in `git remote -v`")
46+
itutils.Execute(t, cmd, params, true, "Not found")
4747
}
4848

4949
func appsDestroyTest(t *testing.T, params *itutils.DeisTestConfig) {
@@ -73,6 +73,9 @@ func appsLogsTest(t *testing.T, params *itutils.DeisTestConfig) {
7373
t.Fatalf("Failed:\n%v", err)
7474
}
7575
itutils.Execute(t, cmd1, params, false, "")
76+
// TODO: nginx needs a few seconds to wake up here--fixme!
77+
time.Sleep(5000 * time.Millisecond)
78+
itutils.Curl(t, params)
7679
itutils.Execute(t, cmd, params, false, "")
7780
if err := utils.Chdir(".."); err != nil {
7881
t.Fatalf("Failed:\n%v", err)

tests/builds_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616

1717
func buildSetup(t *testing.T) *itutils.DeisTestConfig {
1818
cfg := itutils.GetGlobalConfig()
19-
cfg.ExampleApp = itutils.GetRandomApp()
2019
cfg.AppName = "buildsample"
2120
cmd := itutils.GetCommand("auth", "login")
2221
itutils.Execute(t, cmd, cfg, false, "")

tests/config_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
func configSetup(t *testing.T) *itutils.DeisTestConfig {
1414
cfg := itutils.GetGlobalConfig()
15-
cfg.ExampleApp = itutils.GetRandomApp()
1615
cfg.AppName = "configsample"
1716
cmd := itutils.GetCommand("auth", "login")
1817
itutils.Execute(t, cmd, cfg, false, "")

tests/integration-utils/itutils.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
// Deis points to the CLI used to run tests.
2222
var Deis = "deis "
2323

24-
// DeisTestConfig holds paramters needed to run tests.
24+
// DeisTestConfig allows tests to be repeated against different
25+
// targets, with different example apps, using specific credentials, and so on.
2526
type DeisTestConfig struct {
2627
AuthKey string
2728
Hosts string
@@ -39,9 +40,12 @@ type DeisTestConfig struct {
3940
AppUser string
4041
}
4142

43+
// randomApp is used for the test run if DEIS_TEST_APP isn't set
44+
var randomApp = GetRandomApp()
45+
4246
// GetGlobalConfig returns a test configuration object.
4347
func GetGlobalConfig() *DeisTestConfig {
44-
authKey := os.Getenv("AUTH_KEY")
48+
authKey := os.Getenv("DEIS_TEST_AUTH_KEY")
4549
if authKey == "" {
4650
authKey = "deis"
4751
}
@@ -59,7 +63,7 @@ func GetGlobalConfig() *DeisTestConfig {
5963
}
6064
exampleApp := os.Getenv("DEIS_TEST_APP")
6165
if exampleApp == "" {
62-
exampleApp = "example-go"
66+
exampleApp = randomApp
6367
}
6468
var envCfg = DeisTestConfig{
6569
AuthKey: authKey,
@@ -143,9 +147,7 @@ func CheckList(t *testing.T, params interface{}, cmd, contain string, notflag bo
143147
cmdl = exec.Command("sh", "-c", Deis+cmdString)
144148
}
145149
if stdout, _, err := utils.RunCommandWithStdoutStderr(cmdl); err == nil {
146-
if strings.Contains(stdout.String(), contain) != notflag {
147-
fmt.Println("Command Executed perfectly")
148-
} else {
150+
if strings.Contains(stdout.String(), contain) == notflag {
149151
t.Fatal(err)
150152
}
151153
} else {
@@ -178,13 +180,13 @@ func Execute(t *testing.T, cmd string, params interface{}, failFlag bool, expect
178180
case true:
179181
if stdout, stderr, err := utils.RunCommandWithStdoutStderr(cmdl); err != nil {
180182
if strings.Contains(stdout.String(), expect) || strings.Contains(stderr.String(), expect) {
181-
fmt.Println("Test Failed Expected behavior")
183+
fmt.Println("(Error expected...ok)")
182184
} else {
183185
t.Fatalf("Failed:\n%v", err)
184186
}
185187
} else {
186188
if strings.Contains(stdout.String(), expect) || strings.Contains(stderr.String(), expect) {
187-
fmt.Println("expected" + expect)
189+
fmt.Println("(Error expected...ok)" + expect)
188190
} else {
189191
t.Fatalf("Failed:\n%v", err)
190192
}

tests/keys_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
package tests
44

55
import (
6-
_ "fmt"
76
"testing"
87

98
"github.com/deis/deis/tests/integration-utils"
109
)
1110

11+
// Requires a ~/.ssh/deis-testkey to be set up:
12+
// $ ssh-keygen -q -t rsa -f ~/.ssh/deiskey -N '' -C deiskey
1213
func keysSetup(t *testing.T) *itutils.DeisTestConfig {
1314
cfg := itutils.GetGlobalConfig()
1415
cmd := itutils.GetCommand("auth", "login")
@@ -20,7 +21,7 @@ func keysAddTest(t *testing.T, params *itutils.DeisTestConfig) {
2021
cmd := itutils.GetCommand("keys", "add")
2122
params.AuthKey = "deiskey"
2223
itutils.Execute(t, cmd, params, false, "")
23-
itutils.Execute(t, cmd, params, true, "Uploading deiskey to Deis...400 BAD REQUEST")
24+
itutils.Execute(t, cmd, params, true, "SSH Key with this Public already exists")
2425
}
2526

2627
func keysListTest(t *testing.T, params *itutils.DeisTestConfig, notflag bool) {

tests/perms_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
func permsSetup(t *testing.T) *itutils.DeisTestConfig {
1414
cfg := itutils.GetGlobalConfig()
15-
cfg.ExampleApp = itutils.GetRandomApp()
1615
cfg.AppName = "permssample"
1716
cmd := itutils.GetCommand("auth", "login")
1817
itutils.Execute(t, cmd, cfg, false, "")

tests/ps_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package tests
44

55
import (
66
_ "fmt"
7+
"strings"
78
"testing"
89

910
"github.com/deis/deis/tests/integration-utils"
@@ -12,7 +13,6 @@ import (
1213

1314
func psSetup(t *testing.T) *itutils.DeisTestConfig {
1415
cfg := itutils.GetGlobalConfig()
15-
cfg.ExampleApp = itutils.GetRandomApp()
1616
cfg.AppName = "pssample"
1717
cmd := itutils.GetCommand("auth", "login")
1818
itutils.Execute(t, cmd, cfg, false, "")
@@ -34,11 +34,18 @@ func psSetup(t *testing.T) *itutils.DeisTestConfig {
3434

3535
func psListTest(t *testing.T, params *itutils.DeisTestConfig, notflag bool) {
3636
cmd := itutils.GetCommand("ps", "list")
37-
itutils.CheckList(t, params, cmd, "web.2 up (v2)", notflag)
37+
output := "web.2 up (v2)"
38+
if strings.Contains(params.ExampleApp, "dockerfile") {
39+
output = strings.Replace(output, "web", "cmd", 1)
40+
}
41+
itutils.CheckList(t, params, cmd, output, notflag)
3842
}
3943

4044
func psScaleTest(t *testing.T, params *itutils.DeisTestConfig) {
4145
cmd := itutils.GetCommand("ps", "scale")
46+
if strings.Contains(params.ExampleApp, "dockerfile") {
47+
cmd = strings.Replace(cmd, "web", "cmd", 1)
48+
}
4249
itutils.Execute(t, cmd, params, false, "")
4350
}
4451

tests/releases_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
func releasesSetup(t *testing.T) *itutils.DeisTestConfig {
1414
cfg := itutils.GetGlobalConfig()
15-
cfg.ExampleApp = itutils.GetRandomApp()
1615
cfg.AppName = "releasessample"
1716
cmd := itutils.GetCommand("auth", "login")
1817
itutils.Execute(t, cmd, cfg, false, "")

tests/smoke_test.go

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,9 @@ import (
1111
"strings"
1212
"testing"
1313
"text/template"
14-
)
15-
16-
// A Deis test configuration allows tests to be repeated against different
17-
// targets, with different example apps, using specific credentials, and so on.
18-
type deisTestConfig struct {
19-
AuthKey string
20-
ExampleApp string
21-
Hosts string
22-
Domain string
23-
SSHKey string
24-
}
2514

26-
// Test configuration created from environment variables (at compile time).
27-
var envCfg = deisTestConfig{
28-
os.Getenv("AUTH_KEY"),
29-
os.Getenv("DEIS_TEST_APP"),
30-
os.Getenv("DEIS_TEST_HOSTS"),
31-
os.Getenv("DEIS_TEST_DOMAIN"),
32-
os.Getenv("DEIS_TEST_SSH_KEY"),
33-
}
15+
"github.com/deis/deis/tests/integration-utils"
16+
)
3417

3518
// A test case is a relative directory plus a command that is expected to
3619
// return 0 for success.
@@ -111,36 +94,21 @@ sleep 7 && curl -s http://testing.{{.Domain}} | grep -q 'Powered by Deis' || \
11194
`},
11295
}
11396

114-
// Updates a Vagrant instance to run Deis with docker containers using the
115-
// current codebase, then registers a user, pushes an example app, and looks
116-
// for "Powered by Deis" in the HTTP response.
97+
// TestSmokeExampleApp updates a Vagrant instance to run Deis with docker
98+
// containers using the current codebase, then registers a user, pushes an
99+
// example app, and looks for "Powered by Deis" in the HTTP response.
117100
func TestSmokeExampleApp(t *testing.T) {
118-
cfg := envCfg
119-
if cfg.AuthKey == "" {
120-
cfg.AuthKey = "~/.ssh/deis"
121-
}
122-
if cfg.ExampleApp == "" {
123-
cfg.ExampleApp = "example-ruby-sinatra"
124-
}
125-
if cfg.Hosts == "" {
126-
cfg.Hosts = "local.deisapp.com"
127-
}
128-
if cfg.Domain == "" {
129-
cfg.Domain = "local.deisapp.com"
130-
}
131-
if cfg.SSHKey == "" {
132-
cfg.SSHKey = "~/.vagrant.d/insecure_private_key"
133-
}
101+
cfg := itutils.GetGlobalConfig()
134102

135103
for _, tt := range smokeTests {
136-
runTest(t, &tt, &cfg)
104+
runTest(t, &tt, cfg)
137105
}
138106
}
139107

140108
var wd, _ = os.Getwd()
141109

142110
// Runs a test case and logs the results.
143-
func runTest(t *testing.T, tt *deisTest, cfg *deisTestConfig) {
111+
func runTest(t *testing.T, tt *deisTest, cfg *itutils.DeisTestConfig) {
144112
// Fill in the command string template from our test configuration.
145113
var cmdBuf bytes.Buffer
146114
tmpl := template.Must(template.New("cmd").Parse(tt.cmd))
@@ -161,10 +129,6 @@ func runTest(t *testing.T, tt *deisTest, cfg *deisTestConfig) {
161129
t.Fatal(err)
162130
}
163131
}
164-
// TODO: Go's testing package doesn't seem to allow for reporting interim
165-
// progress--we have to wait until everything completes (or fails) to see
166-
// anything that was written with t.Log or t.Fatal. Interim output would
167-
// be extremely helpful here, as this takes a while.
168132
// Execute the command and log the input and output on error.
169133
fmt.Printf("%v ... ", strings.TrimSpace(cmdString))
170134
cmd := exec.Command("sh", "-c", cmdString)

tests/testconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"unset" : "config:unset jaf --app={{.AppName}}"
5555
},
5656
"git" : {
57-
"clone" : "git clone https://github.com/deis/{{.ExampleApp}}.git",
57+
"clone" : "if [ ! -d {{.ExampleApp}} ] ; then git clone https://github.com/deis/{{.ExampleApp}}.git ; fi",
5858
"remove" : "git remote remove deis",
5959
"push" : "git push deis master",
6060
"add" : "git add .",

0 commit comments

Comments
 (0)