github.com/spg/deis@v1.7.3/tests/apps_test.go (about) 1 // +build integration 2 3 package tests 4 5 import ( 6 "fmt" 7 "math/rand" 8 "os" 9 "testing" 10 11 "github.com/deis/deis/tests/utils" 12 ) 13 14 var ( 15 appsCreateCmd = "apps:create {{.AppName}}" 16 appsCreateCmdNoRemote = "apps:create {{.AppName}} --no-remote" 17 appsCreateCmdBuildpack = "apps:create {{.AppName}} --buildpack https://example.com" 18 appsListCmd = "apps:list" 19 appsRunCmd = "apps:run echo Hello, 世界" 20 appsOpenCmd = "apps:open --app={{.AppName}}" 21 appsLogsCmd = "apps:logs --app={{.AppName}}" 22 appsLogsLimitCmd = "apps:logs --app={{.AppName}} -n 1" 23 appsInfoCmd = "apps:info --app={{.AppName}}" 24 appsDestroyCmd = "apps:destroy --app={{.AppName}} --confirm={{.AppName}}" 25 appsDestroyCmdNoApp = "apps:destroy --confirm={{.AppName}}" 26 ) 27 28 func randomString(n int) string { 29 var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") 30 b := make([]rune, n) 31 for i := range b { 32 b[i] = letters[rand.Intn(len(letters))] 33 } 34 return string(b) 35 } 36 37 func TestApps(t *testing.T) { 38 params := appsSetup(t) 39 appsCreateTest(t, params) 40 appsListTest(t, params, false) 41 appsLogsTest(t, params) 42 appsInfoTest(t, params) 43 appsRunTest(t, params) 44 appsOpenTest(t, params) 45 appsDestroyTest(t, params) 46 appsListTest(t, params, true) 47 } 48 49 func appsSetup(t *testing.T) *utils.DeisTestConfig { 50 cfg := utils.GetGlobalConfig() 51 cfg.AppName = "appssample" 52 utils.Execute(t, authLoginCmd, cfg, false, "") 53 utils.Execute(t, gitCloneCmd, cfg, false, "") 54 return cfg 55 } 56 57 func appsCreateTest(t *testing.T, params *utils.DeisTestConfig) { 58 wd, _ := os.Getwd() 59 defer os.Chdir(wd) 60 if err := utils.Chdir(params.ExampleApp); err != nil { 61 t.Fatal(err) 62 } 63 // TODO: move --buildpack to client unit tests 64 utils.Execute(t, appsCreateCmdBuildpack, params, false, "BUILDPACK_URL") 65 utils.Execute(t, appsDestroyCmdNoApp, params, false, "") 66 utils.Execute(t, appsCreateCmd, params, false, "") 67 utils.Execute(t, appsCreateCmd, params, true, "This field must be unique.") 68 } 69 70 func appsDestroyTest(t *testing.T, params *utils.DeisTestConfig) { 71 if err := utils.Chdir(params.ExampleApp); err != nil { 72 t.Fatal(err) 73 } 74 utils.Execute(t, appsDestroyCmd, params, false, "") 75 if err := utils.Chdir(".."); err != nil { 76 t.Fatal(err) 77 } 78 if err := utils.Rmdir(params.ExampleApp); err != nil { 79 t.Fatal(err) 80 } 81 } 82 83 func appsInfoTest(t *testing.T, params *utils.DeisTestConfig) { 84 utils.Execute(t, appsInfoCmd, params, false, "") 85 } 86 87 func appsListTest(t *testing.T, params *utils.DeisTestConfig, notflag bool) { 88 utils.CheckList(t, appsListCmd, params, params.AppName, notflag) 89 } 90 91 func appsLogsTest(t *testing.T, params *utils.DeisTestConfig) { 92 cmd := appsLogsCmd 93 // test for application lifecycle logs 94 utils.Execute(t, cmd, params, false, "204 NO CONTENT") 95 if err := utils.Chdir(params.ExampleApp); err != nil { 96 t.Fatal(err) 97 } 98 utils.Execute(t, gitPushCmd, params, false, "") 99 utils.CurlApp(t, *params) 100 utils.Execute(t, cmd, params, false, "created initial release") 101 utils.Execute(t, cmd, params, false, "listening on 5000...") 102 103 utils.Execute(t, appsLogsLimitCmd, params, false, "") 104 105 if err := utils.Chdir(".."); err != nil { 106 t.Fatal(err) 107 } 108 } 109 110 func appsOpenTest(t *testing.T, params *utils.DeisTestConfig) { 111 utils.CurlApp(t, *params) 112 utils.CurlWithFail(t, fmt.Sprintf("http://%s.%s", "this-app-does-not-exist", params.Domain), true, "404 Not Found") 113 } 114 115 func appsRunTest(t *testing.T, params *utils.DeisTestConfig) { 116 cmd := appsRunCmd 117 if err := utils.Chdir(params.ExampleApp); err != nil { 118 t.Fatal(err) 119 } 120 utils.CheckList(t, cmd, params, "Hello, 世界", false) 121 utils.Execute(t, "apps:run env", params, true, "GIT_SHA") 122 // run a REALLY large command to test https://github.com/deis/deis/issues/2046 123 largeString := randomString(1024) 124 utils.Execute(t, "apps:run echo "+largeString, params, false, largeString) 125 if err := utils.Chdir(".."); err != nil { 126 t.Fatal(err) 127 } 128 utils.Execute(t, cmd, params, true, "Not found") 129 }