github.com/rochacon/deis@v1.0.2-0.20150903015341-6839b592a1ff/tests/config_test.go (about) 1 // +build integration 2 3 package tests 4 5 import ( 6 "io/ioutil" 7 "strings" 8 "testing" 9 10 "github.com/deis/deis/tests/utils" 11 ) 12 13 var ( 14 configListCmd = "config:list --app={{.AppName}}" 15 configSetCmd = "config:set FOO=讲台 --app={{.AppName}}" 16 configSet2Cmd = "config:set FOO=10 --app={{.AppName}}" 17 configSet3Cmd = "config:set POWERED_BY=\"the Deis team\" --app={{.AppName}}" 18 configSetBuildpackCmd = "config:set BUILDPACK_URL=$BUILDPACK_URL --app={{.AppName}}" 19 configUnsetCmd = "config:unset FOO --app={{.AppName}}" 20 ) 21 22 var buildpacks = map[string]string{ 23 "example-clojure-ring": "https://github.com/heroku/heroku-buildpack-clojure#v66", 24 "example-go": "https://github.com/heroku/heroku-buildpack-go#6eeb09f", 25 "example-java-jetty": "https://github.com/heroku/heroku-buildpack-java#v38", 26 "example-nodejs-express": "https://github.com/heroku/heroku-buildpack-nodejs#v75", 27 "example-perl": "https://github.com/miyagawa/heroku-buildpack-perl#2da7480", 28 "example-php": "https://github.com/heroku/heroku-buildpack-php#v67", 29 "example-play": "https://github.com/heroku/heroku-buildpack-play#v23", 30 "example-python-django": "https://github.com/heroku/heroku-buildpack-python#v58", 31 "example-python-flask": "https://github.com/heroku/heroku-buildpack-python#v58", 32 "example-ruby-sinatra": "https://github.com/heroku/heroku-buildpack-ruby#v137", 33 "example-scala": "https://github.com/heroku/heroku-buildpack-scala#v55", 34 } 35 36 func TestConfig(t *testing.T) { 37 params := configSetup(t) 38 configSetTest(t, params) 39 configPushTest(t, params) 40 configListTest(t, params, false) 41 appsOpenTest(t, params) 42 configUnsetTest(t, params) 43 configListTest(t, params, true) 44 limitsSetTest(t, params, 4) 45 appsOpenTest(t, params) 46 limitsUnsetTest(t, params, 6) 47 appsOpenTest(t, params) 48 //tagsTest(t, params, 8) 49 appsOpenTest(t, params) 50 utils.AppsDestroyTest(t, params) 51 } 52 53 func configSetup(t *testing.T) *utils.DeisTestConfig { 54 cfg := utils.GetGlobalConfig() 55 cfg.AppName = "configsample" 56 utils.Execute(t, authLoginCmd, cfg, false, "") 57 utils.Execute(t, gitCloneCmd, cfg, false, "") 58 if err := utils.Chdir(cfg.ExampleApp); err != nil { 59 t.Fatal(err) 60 } 61 utils.Execute(t, appsCreateCmd, cfg, false, "") 62 // ensure envvars with spaces work fine on `git push` 63 // https://github.com/deis/deis/issues/2477 64 utils.Execute(t, configSet3Cmd, cfg, false, "the Deis team") 65 // ensure custom buildpack URLs are in order 66 url := buildpacks[cfg.ExampleApp] 67 if url == "" { 68 // set url anyway so example-dockerfile apps create a build 69 url = buildpacks["example-go"] 70 } 71 cmd := strings.Replace(configSetBuildpackCmd, "$BUILDPACK_URL", url, 1) 72 utils.Execute(t, cmd, cfg, false, url) 73 utils.Execute(t, gitPushCmd, cfg, false, "") 74 utils.CurlApp(t, *cfg) 75 utils.CheckList(t, "run env --app={{.AppName}}", cfg, "DEIS_APP", false) 76 utils.CheckList(t, "run env --app={{.AppName}}", cfg, "DEIS_RELEASE", false) 77 if err := utils.Chdir(".."); err != nil { 78 t.Fatal(err) 79 } 80 return cfg 81 } 82 83 func configListTest( 84 t *testing.T, params *utils.DeisTestConfig, notflag bool) { 85 utils.CheckList(t, configListCmd, params, "FOO", notflag) 86 } 87 88 func configSetTest(t *testing.T, params *utils.DeisTestConfig) { 89 utils.Execute(t, configSetCmd, params, false, "讲台") 90 utils.CheckList(t, appsInfoCmd, params, "(v5)", false) 91 utils.Execute(t, configSet2Cmd, params, false, "10") 92 utils.CheckList(t, appsInfoCmd, params, "(v6)", false) 93 } 94 95 func configPushTest(t *testing.T, params *utils.DeisTestConfig) { 96 if err := utils.Chdir(params.ExampleApp); err != nil { 97 t.Fatal(err) 98 } 99 // create a .env in the project root 100 if err := ioutil.WriteFile(".env", []byte("POWERED_BY=Deis"), 0664); err != nil { 101 t.Fatal(err) 102 } 103 utils.Execute(t, "config:push --app {{.AppName}}", params, false, "Deis") 104 utils.CheckList(t, appsInfoCmd, params, "(v7)", false) 105 if err := utils.Chdir(".."); err != nil { 106 t.Fatal(err) 107 } 108 } 109 110 func configUnsetTest(t *testing.T, params *utils.DeisTestConfig) { 111 utils.Execute(t, configUnsetCmd, params, false, "") 112 utils.CheckList(t, appsInfoCmd, params, "(v8)", false) 113 utils.CheckList(t, "run env --app={{.AppName}}", params, "FOO", true) 114 }