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