-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapps_test.go
More file actions
146 lines (129 loc) · 4.62 KB
/
apps_test.go
File metadata and controls
146 lines (129 loc) · 4.62 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// +build integration
package tests
import (
"fmt"
"math/rand"
"os"
"testing"
"github.com/deis/deis/tests/utils"
)
var (
appsCreateCmd = "apps:create {{.AppName}}"
appsCreateCmdNoRemote = "apps:create {{.AppName}} --no-remote"
appsCreateCmdBuildpack = "apps:create {{.AppName}} --buildpack https://example.com"
appsListCmd = "apps:list"
appsRunCmd = "apps:run echo Hello, 世界"
appsOpenCmd = "apps:open --app={{.AppName}}"
appsLogsCmd = "apps:logs --app={{.AppName}}"
appsLogsLimitCmd = "apps:logs --app={{.AppName}} -n 1"
appsInfoCmd = "apps:info --app={{.AppName}}"
appsDestroyCmd = "apps:destroy --app={{.AppName}} --confirm={{.AppName}}"
appsDestroyCmdNoApp = "apps:destroy --confirm={{.AppName}}"
appsTransferCmd = "apps:transfer {{.NewOwner}} --app={{.AppName}}"
)
func randomString(n int) string {
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
func TestApps(t *testing.T) {
params := appsSetup(t)
appsCreateTest(t, params)
appsListTest(t, params, false)
appsLogsTest(t, params)
appsInfoTest(t, params)
appsRunTest(t, params)
appsOpenTest(t, params)
appsDestroyTest(t, params)
appsListTest(t, params, true)
appsTransferTest(t, params)
}
func appsSetup(t *testing.T) *utils.DeisTestConfig {
cfg := utils.GetGlobalConfig()
cfg.AppName = "appssample"
utils.Execute(t, authLoginCmd, cfg, false, "")
utils.Execute(t, gitCloneCmd, cfg, false, "")
return cfg
}
func appsCreateTest(t *testing.T, params *utils.DeisTestConfig) {
wd, _ := os.Getwd()
defer os.Chdir(wd)
if err := utils.Chdir(params.ExampleApp); err != nil {
t.Fatal(err)
}
// TODO: move --buildpack to client unit tests
utils.Execute(t, appsCreateCmdBuildpack, params, false, "BUILDPACK_URL")
utils.Execute(t, appsDestroyCmdNoApp, params, false, "")
utils.Execute(t, appsCreateCmd, params, false, "")
utils.Execute(t, appsCreateCmd, params, true, "This field must be unique.")
}
func appsDestroyTest(t *testing.T, params *utils.DeisTestConfig) {
if err := utils.Chdir(params.ExampleApp); err != nil {
t.Fatal(err)
}
utils.Execute(t, appsDestroyCmd, params, false, "")
if err := utils.Chdir(".."); err != nil {
t.Fatal(err)
}
if err := utils.Rmdir(params.ExampleApp); err != nil {
t.Fatal(err)
}
}
func appsInfoTest(t *testing.T, params *utils.DeisTestConfig) {
utils.Execute(t, appsInfoCmd, params, false, "")
}
func appsListTest(t *testing.T, params *utils.DeisTestConfig, notflag bool) {
utils.CheckList(t, appsListCmd, params, params.AppName, notflag)
}
func appsLogsTest(t *testing.T, params *utils.DeisTestConfig) {
cmd := appsLogsCmd
// test for application lifecycle logs
utils.Execute(t, cmd, params, false, "204 NO CONTENT")
if err := utils.Chdir(params.ExampleApp); err != nil {
t.Fatal(err)
}
utils.Execute(t, gitPushCmd, params, false, "")
utils.CurlApp(t, *params)
utils.Execute(t, cmd, params, false, "created initial release")
utils.Execute(t, cmd, params, false, "listening on 5000...")
utils.Execute(t, appsLogsLimitCmd, params, false, "")
if err := utils.Chdir(".."); err != nil {
t.Fatal(err)
}
}
func appsOpenTest(t *testing.T, params *utils.DeisTestConfig) {
utils.CurlApp(t, *params)
utils.CurlWithFail(t, fmt.Sprintf("http://%s.%s", "this-app-does-not-exist", params.Domain), true, "404 Not Found")
}
func appsRunTest(t *testing.T, params *utils.DeisTestConfig) {
cmd := appsRunCmd
if err := utils.Chdir(params.ExampleApp); err != nil {
t.Fatal(err)
}
utils.CheckList(t, cmd, params, "Hello, 世界", false)
utils.Execute(t, "apps:run env", params, true, "GIT_SHA")
// run a REALLY large command to test https://github.com/deis/deis/issues/2046
largeString := randomString(1024)
utils.Execute(t, "apps:run echo "+largeString, params, false, largeString)
if err := utils.Chdir(".."); err != nil {
t.Fatal(err)
}
utils.Execute(t, cmd, params, true, "Not found")
}
func appsTransferTest(t *testing.T, params *utils.DeisTestConfig) {
user := utils.GetGlobalConfig()
user.UserName, user.Password = "app-transfer-test", "test"
user.AppName = "transfer-test"
user.NewOwner = params.UserName
utils.Execute(t, authRegisterCmd, user, false, "")
utils.Execute(t, authLoginCmd, user, false, "")
utils.Execute(t, appsCreateCmdNoRemote, user, false, "")
utils.Execute(t, appsTransferCmd, user, false, "")
utils.Execute(t, appsInfoCmd, user, true, "403 FORBIDDEN")
utils.Execute(t, authLoginCmd, params, false, "")
params.AppName = user.AppName
utils.CheckList(t, appsInfoCmd, params, params.UserName, false)
}