Skip to content

Commit cf90e84

Browse files
smothikimboersma
authored andcommitted
test(integration): add regression tests for two issues
See github issues #1136 and #1239. Removed example-play as its taking too much time. Added `curl` test for each test that launches an app.
1 parent 752feea commit cf90e84

8 files changed

Lines changed: 63 additions & 24 deletions

File tree

integration/apps_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
func appsSetup(t *testing.T) *itutils.DeisTestConfig {
1010
cfg := itutils.GetGlobalConfig()
11+
cfg.AppName = "appssample"
1112
cfg.ExampleApp = itutils.GetRandomApp()
1213
cmd := itutils.GetCommand("auth", "login")
1314
itutils.Execute(t, cmd, cfg, false, "")
@@ -48,7 +49,6 @@ func appsDestroyTest(t *testing.T, params *itutils.DeisTestConfig) {
4849
t.Fatalf("Failed:\n%v", err)
4950
}
5051
itutils.Execute(t, cmd, params, false, "")
51-
itutils.Execute(t, cmd, params, true, "400 BAD REQUEST")
5252
if err := utils.Chdir(".."); err != nil {
5353
t.Fatalf("Failed:\n%v", err)
5454
}
@@ -82,7 +82,7 @@ func appsInfoTest(t *testing.T, params *itutils.DeisTestConfig) {
8282
}
8383

8484
func appsOpenTest(t *testing.T, params *itutils.DeisTestConfig) {
85-
itutils.Curl(t, "http://"+params.AppName+"."+params.HostName, params.ExampleApp)
85+
itutils.Curl(t, params)
8686
}
8787

8888
func TestApps(t *testing.T) {

integration/builds_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,14 @@ func buildsCreateTest(t *testing.T, params *itutils.DeisTestConfig) {
6767

6868
}
6969

70+
func appsOpenTest(t *testing.T, params *itutils.DeisTestConfig) {
71+
itutils.Curl(t, params)
72+
}
73+
7074
func TestBuilds(t *testing.T) {
7175
params := buildSetup(t)
7276
buildsListTest(t, params)
7377
buildsCreateTest(t, params)
78+
appsOpenTest(t, params)
7479
itutils.AppsDestroyTest(t, params)
7580
}

integration/cluster_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ func clustersInfoTest(t *testing.T, params *itutils.DeisTestConfig) {
3030
itutils.Execute(t, cmd, params, false, "")
3131
}
3232

33+
//Tets #1283
34+
3335
func clustersUpdateTest(t *testing.T, params *itutils.DeisTestConfig) {
3436
cmd := itutils.GetCommand("clusters", "update")
35-
itutils.Execute(t, cmd, params, false, "")
37+
itutils.CheckList(t, params, cmd, "~/.ssh/"+params.AuthKey, true)
3638
}
3739

3840
func clustersDestroyTest(t *testing.T, params *itutils.DeisTestConfig) {

integration/config_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package verbose
33
import (
44
_ "fmt"
55
"github.com/deis/deis/tests/integration-utils"
6-
_ "github.com/deis/deis/tests/utils"
6+
"github.com/deis/deis/tests/utils"
77
"testing"
88
)
99

@@ -38,19 +38,24 @@ func configlistTest(t *testing.T, params *itutils.DeisTestConfig, notflag bool)
3838
func configSetTest(t *testing.T, params *itutils.DeisTestConfig) {
3939
cmd := itutils.GetCommand("config", "set")
4040
itutils.Execute(t, cmd, params, false, "")
41-
itutils.CheckList(t, params, itutils.GetCommand("apps", "info"), "web.1 up (v3)")
41+
itutils.CheckList(t, params, itutils.GetCommand("apps", "info"), "(v3)", false)
4242
}
4343

4444
func configUnsetTest(t *testing.T, params *itutils.DeisTestConfig) {
4545
cmd := itutils.GetCommand("config", "unset")
4646
itutils.Execute(t, cmd, params, false, "")
47-
itutils.CheckList(t, params, itutils.GetCommand("apps", "info"), "web.1 up (v4)")
47+
itutils.CheckList(t, params, itutils.GetCommand("apps", "info"), "(v4)", false)
48+
}
49+
50+
func appsOpenTest(t *testing.T, params *itutils.DeisTestConfig) {
51+
itutils.Curl(t, params)
4852
}
4953

5054
func TestConfig(t *testing.T) {
5155
params := configSetup(t)
5256
configSetTest(t, params)
5357
configlistTest(t, params, false)
58+
appsOpenTest(t, params)
5459
configUnsetTest(t, params)
5560
configlistTest(t, params, true)
5661
itutils.AppsDestroyTest(t, params)

integration/integration_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@ import (
55
"testing"
66
)
77

8-
func authcancelTest(t *testing.T, params *itutils.DeisTestConfig) {
8+
//Tests #1136 // Tests #1239
9+
func cookieTest(t *testing.T, params *itutils.DeisTestConfig) {
910
var cmd string
1011
cmd = itutils.GetCommand("auth", "register")
1112
itutils.Execute(t, cmd, params, false, "")
13+
itutils.CheckList(t, params, "cat ~/.deis/cookies.txt", "csrftoken", false)
14+
itutils.CheckList(t, params, "cat ~/.deis/cookies.txt", "sessionid", false)
1215
itutils.AuthCancel(t, params)
16+
itutils.CheckList(t, params, "cat ~/.deis/cookies.txt", "csrftoken", true)
17+
itutils.CheckList(t, params, "cat ~/.deis/cookies.txt", "sessionid", true)
1318
}
1419

1520
func TestGlobal(t *testing.T) {
1621
params := itutils.GetGlobalConfig()
1722
var cmd string
18-
authcancelTest(t, params)
23+
cookieTest(t, params)
1924
cmd = itutils.GetCommand("auth", "register")
2025
itutils.Execute(t, cmd, params, false, "")
2126
cmd = itutils.GetCommand("keys", "add")

integration/ps_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func psScaleTest(t *testing.T, params *itutils.DeisTestConfig) {
4242
func TestBuilds(t *testing.T) {
4343
params := psSetup(t)
4444
psScaleTest(t, params)
45+
appsOpenTest(t, params)
4546
psListTest(t, params, false)
4647
itutils.AppsDestroyTest(t, params)
4748
cmd := itutils.GetCommand("ps", "list")

integration/releases_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,16 @@ func releasesRollbackTest(t *testing.T, params *itutils.DeisTestConfig) {
4545
itutils.Execute(t, cmd, params, false, "")
4646
}
4747

48+
func appsOpenTest(t *testing.T, params *itutils.DeisTestConfig) {
49+
itutils.Curl(t, params)
50+
}
51+
4852
func TestReleases(t *testing.T) {
4953
params := releasesSetup(t)
5054
releasesListTest(t, params, false)
5155
releasesInfoTest(t, params)
5256
releasesRollbackTest(t, params)
57+
appsOpenTest(t, params)
5358
params.Version = "4"
5459
releasesListTest(t, params, false)
5560
itutils.AppsDestroyTest(t, params)

tests/integration-utils/itutils.go

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package itutils
33
import (
44
"bytes"
55
"fmt"
6+
"github.com/ThomasRooney/gexpect"
67
gson "github.com/bitly/go-simplejson"
78
"github.com/deis/deis/tests/utils"
89
"io/ioutil"
@@ -13,7 +14,6 @@ import (
1314
"testing"
1415
"text/template"
1516
"time"
16-
"github.com/ThomasRooney/gexpect"
1717
)
1818

1919
var Deis = "/usr/local/bin/deis "
@@ -33,7 +33,7 @@ type DeisTestConfig struct {
3333
ProcessNum string
3434
ImageId string
3535
Version string
36-
AppUser string
36+
AppUser string
3737
}
3838

3939
func GetGlobalConfig() *DeisTestConfig {
@@ -57,24 +57,28 @@ func GetGlobalConfig() *DeisTestConfig {
5757
return &envCfg
5858
}
5959

60-
func Curl(t *testing.T, url string, exampleApp string) {
60+
//Tests example apps are running or not
61+
62+
func Curl(t *testing.T, params *DeisTestConfig) {
63+
url := "http://" + params.AppName + "." + params.HostName
6164
response, err := http.Get(url)
6265
if err != nil {
6366
t.Fatalf("not reachable:\n%v", err)
6467
}
6568
body, err := ioutil.ReadAll(response.Body)
6669
fmt.Println(string(body))
67-
if exampleApp == "example-python-django" {
70+
if params.AppName == "example-python-django" {
6871
if !strings.Contains(string(body), "Powered by django") {
6972
t.Fatalf("App not started")
7073
}
71-
}else if !strings.Contains(string(body), "Powered by Deis") {
74+
} else if !strings.Contains(string(body), "Powered by Deis") {
7275
t.Fatalf("App not started")
7376
}
7477
}
7578

79+
//gexpect implementation of auth cancel
7680

77-
func AuthCancel(t *testing.T, params *DeisTestConfig){
81+
func AuthCancel(t *testing.T, params *DeisTestConfig) {
7882
fmt.Println("deis auth:cancel")
7983
child, err := gexpect.Spawn("/usr/local/bin/deis auth:cancel")
8084
if err != nil {
@@ -105,15 +109,23 @@ func AuthCancel(t *testing.T, params *DeisTestConfig){
105109

106110
}
107111

108-
func CheckList(t *testing.T, params interface{}, cmd, contain string,notflag bool) {
112+
/*CheckList takes config , command to execute and contain string and notflag .
113+
* Executes the command and checks if the contain string should be present or not according to notflag */
114+
115+
func CheckList(t *testing.T, params interface{}, cmd, contain string, notflag bool) {
109116
var cmdBuf bytes.Buffer
110117
tmpl := template.Must(template.New("cmd").Parse(cmd))
111118
if err := tmpl.Execute(&cmdBuf, params); err != nil {
112119
t.Fatal(err)
113120
}
114121
cmdString := cmdBuf.String()
115122
fmt.Println(cmdString)
116-
cmdl := exec.Command("sh", "-c", Deis+cmdString)
123+
var cmdl *exec.Cmd
124+
if strings.Contains(cmd, "cat") {
125+
cmdl = exec.Command("sh", "-c", cmdString)
126+
} else {
127+
cmdl = exec.Command("sh", "-c", Deis+cmdString)
128+
}
117129
if stdout, _, err := utils.RunCommandWithStdoutStderr(cmdl); err == nil {
118130
if strings.Contains(stdout.String(), contain) != notflag {
119131
fmt.Println("Command Executed perfectly")
@@ -172,6 +184,8 @@ func Execute(t *testing.T, cmd string, params interface{}, failFlag bool, expect
172184
}
173185
}
174186

187+
//Destroys an app after execution of each integration test
188+
175189
func AppsDestroyTest(t *testing.T, params *DeisTestConfig) {
176190
cmd := GetCommand("apps", "destroy")
177191
if err := utils.Chdir(params.ExampleApp); err != nil {
@@ -186,12 +200,15 @@ func AppsDestroyTest(t *testing.T, params *DeisTestConfig) {
186200
}
187201
}
188202

203+
//Fetch commands from testconfig.json
204+
189205
func GetCommand(cmdtype, cmd string) string {
190206
js, _ := gson.NewJson(utils.GetFileBytes("testconfig.json"))
191207
command, _ := js.Get("commands").Get(cmdtype).Get(cmd).String()
192208
return command
193209
}
194210

211+
//Selects a random app
195212

196213
func GetRandomApp() string {
197214
s1 := rand.NewSource(int64(time.Now().Unix()))
@@ -200,13 +217,12 @@ func GetRandomApp() string {
200217
appmap[0] = "example-go"
201218
appmap[1] = "example-ruby-sinatra"
202219
appmap[2] = "example-java-jetty"
203-
appmap[3] = "example-play"
204-
appmap[4] = "example-nodejs-express"
205-
appmap[5] = "example-python-flask"
206-
appmap[6] = "example-dockerfile-python"
207-
appmap[7] = "example-scala"
208-
appmap[8] = "example-clojure-ring"
209-
appmap[9] = "example-python-django"
210-
app := appmap[r1.Intn(9)]
220+
appmap[3] = "example-nodejs-express"
221+
appmap[4] = "example-python-flask"
222+
appmap[5] = "example-dockerfile-python"
223+
appmap[6] = "example-scala"
224+
appmap[7] = "example-clojure-ring"
225+
appmap[8] = "example-python-django"
226+
app := appmap[r1.Intn(8)]
211227
return app
212228
}

0 commit comments

Comments
 (0)