forked from deis/deis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
118 lines (107 loc) · 4.26 KB
/
config_test.go
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
// +build integration
package tests
import (
"io/ioutil"
"strings"
"testing"
"github.com/deis/deis/tests/utils"
)
var (
configListCmd = "config:list --app={{.AppName}}"
configSetCmd = "config:set FOO=讲台 --app={{.AppName}}"
configSet2Cmd = "config:set FOO=10 --app={{.AppName}}"
configSet3Cmd = "config:set POWERED_BY=\"the Deis team\" --app={{.AppName}}"
configSet4Cmd = `config:set FOO="This is a
multiline string" --app={{.AppName}}`
configSetBuildpackCmd = "config:set BUILDPACK_URL=$BUILDPACK_URL --app={{.AppName}}"
configUnsetCmd = "config:unset FOO --app={{.AppName}}"
)
var buildpacks = map[string]string{
"example-clojure-ring": "https://github.com/heroku/heroku-buildpack-clojure#v66",
"example-go": "https://github.com/heroku/heroku-buildpack-go#6eeb09f",
"example-java-jetty": "https://github.com/heroku/heroku-buildpack-java#v38",
"example-nodejs-express": "https://github.com/heroku/heroku-buildpack-nodejs#v75",
"example-perl": "https://github.com/miyagawa/heroku-buildpack-perl#2da7480",
"example-php": "https://github.com/heroku/heroku-buildpack-php#v67",
"example-play": "https://github.com/heroku/heroku-buildpack-play#v23",
"example-python-django": "https://github.com/heroku/heroku-buildpack-python#v58",
"example-python-flask": "https://github.com/heroku/heroku-buildpack-python#v58",
"example-ruby-sinatra": "https://github.com/heroku/heroku-buildpack-ruby#v137",
"example-scala": "https://github.com/heroku/heroku-buildpack-scala#v55",
}
func TestConfig(t *testing.T) {
params := configSetup(t)
configSetTest(t, params)
configPushTest(t, params)
configListTest(t, params, false)
appsOpenTest(t, params)
configUnsetTest(t, params)
configListTest(t, params, true)
limitsSetTest(t, params, 4)
appsOpenTest(t, params)
limitsUnsetTest(t, params, 6)
appsOpenTest(t, params)
//tagsTest(t, params, 8)
appsOpenTest(t, params)
utils.AppsDestroyTest(t, params)
}
func configSetup(t *testing.T) *utils.DeisTestConfig {
cfg := utils.GetGlobalConfig()
cfg.AppName = "configsample"
utils.Execute(t, authLoginCmd, cfg, false, "")
utils.Execute(t, gitCloneCmd, cfg, false, "")
if err := utils.Chdir(cfg.ExampleApp); err != nil {
t.Fatal(err)
}
utils.Execute(t, appsCreateCmd, cfg, false, "")
// ensure envvars with spaces work fine on `git push`
// https://github.com/deis/deis/issues/2477
utils.Execute(t, configSet3Cmd, cfg, false, "the Deis team")
// ensure custom buildpack URLs are in order
url := buildpacks[cfg.ExampleApp]
if url == "" {
// set url anyway so example-dockerfile apps create a build
url = buildpacks["example-go"]
}
cmd := strings.Replace(configSetBuildpackCmd, "$BUILDPACK_URL", url, 1)
utils.Execute(t, cmd, cfg, false, url)
utils.Execute(t, gitPushCmd, cfg, false, "")
utils.CurlApp(t, *cfg)
utils.CheckList(t, "run env --app={{.AppName}}", cfg, "DEIS_APP", false)
utils.CheckList(t, "run env --app={{.AppName}}", cfg, "DEIS_RELEASE", false)
if err := utils.Chdir(".."); err != nil {
t.Fatal(err)
}
return cfg
}
func configListTest(
t *testing.T, params *utils.DeisTestConfig, notflag bool) {
utils.CheckList(t, configListCmd, params, "FOO", notflag)
}
func configSetTest(t *testing.T, params *utils.DeisTestConfig) {
utils.Execute(t, configSetCmd, params, false, "讲台")
utils.CheckList(t, appsInfoCmd, params, "(v5)", false)
utils.Execute(t, configSet2Cmd, params, false, "10")
utils.CheckList(t, appsInfoCmd, params, "(v6)", false)
utils.Execute(t, configSet4Cmd, params, false, "")
utils.CheckList(t, appsInfoCmd, params, "(v7)", false)
}
func configPushTest(t *testing.T, params *utils.DeisTestConfig) {
if err := utils.Chdir(params.ExampleApp); err != nil {
t.Fatal(err)
}
// create a .env in the project root
if err := ioutil.WriteFile(".env", []byte("POWERED_BY=Deis"), 0664); err != nil {
t.Fatal(err)
}
utils.Execute(t, "config:push --app {{.AppName}}", params, false, "Deis")
utils.CheckList(t, appsInfoCmd, params, "(v8)", false)
if err := utils.Chdir(".."); err != nil {
t.Fatal(err)
}
}
func configUnsetTest(t *testing.T, params *utils.DeisTestConfig) {
utils.Execute(t, configUnsetCmd, params, false, "")
utils.CheckList(t, appsInfoCmd, params, "(v9)", false)
utils.CheckList(t, "run env --app={{.AppName}}", params, "FOO", true)
}