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