PageRenderTime 89ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/apps_test.go

https://gitlab.com/seacoastboy/deis
Go | 119 lines | 102 code | 14 blank | 3 comment | 18 complexity | 98868d4f2239cae1b630d19a50d46614 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. // +build integration
  2. package tests
  3. import (
  4. "math/rand"
  5. "os"
  6. "testing"
  7. "github.com/deis/deis/tests/utils"
  8. )
  9. var (
  10. appsCreateCmd = "apps:create {{.AppName}}"
  11. appsCreateCmdNoRemote = "apps:create {{.AppName}} --no-remote"
  12. appsListCmd = "apps:list"
  13. appsRunCmd = "apps:run echo hello"
  14. appsOpenCmd = "apps:open --app={{.AppName}}"
  15. appsLogsCmd = "apps:logs --app={{.AppName}}"
  16. appsInfoCmd = "apps:info --app={{.AppName}}"
  17. appsDestroyCmd = "apps:destroy --app={{.AppName}} --confirm={{.AppName}}"
  18. )
  19. func randomString(n int) string {
  20. var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
  21. b := make([]rune, n)
  22. for i := range b {
  23. b[i] = letters[rand.Intn(len(letters))]
  24. }
  25. return string(b)
  26. }
  27. func TestApps(t *testing.T) {
  28. params := appsSetup(t)
  29. appsCreateTest(t, params)
  30. appsListTest(t, params, false)
  31. appsLogsTest(t, params)
  32. appsInfoTest(t, params)
  33. appsRunTest(t, params)
  34. appsOpenTest(t, params)
  35. appsDestroyTest(t, params)
  36. appsListTest(t, params, true)
  37. }
  38. func appsSetup(t *testing.T) *utils.DeisTestConfig {
  39. cfg := utils.GetGlobalConfig()
  40. cfg.AppName = "appssample"
  41. utils.Execute(t, authLoginCmd, cfg, false, "")
  42. utils.Execute(t, gitCloneCmd, cfg, false, "")
  43. return cfg
  44. }
  45. func appsCreateTest(t *testing.T, params *utils.DeisTestConfig) {
  46. wd, _ := os.Getwd()
  47. defer os.Chdir(wd)
  48. if err := utils.Chdir(params.ExampleApp); err != nil {
  49. t.Fatal(err)
  50. }
  51. cmd := appsCreateCmd
  52. utils.Execute(t, cmd, params, false, "")
  53. utils.Execute(t, cmd, params, true, "App with this Id already exists")
  54. }
  55. func appsDestroyTest(t *testing.T, params *utils.DeisTestConfig) {
  56. if err := utils.Chdir(params.ExampleApp); err != nil {
  57. t.Fatal(err)
  58. }
  59. utils.Execute(t, appsDestroyCmd, params, false, "")
  60. if err := utils.Chdir(".."); err != nil {
  61. t.Fatal(err)
  62. }
  63. if err := utils.Rmdir(params.ExampleApp); err != nil {
  64. t.Fatal(err)
  65. }
  66. }
  67. func appsInfoTest(t *testing.T, params *utils.DeisTestConfig) {
  68. utils.Execute(t, appsInfoCmd, params, false, "")
  69. }
  70. func appsListTest(t *testing.T, params *utils.DeisTestConfig, notflag bool) {
  71. utils.CheckList(t, appsListCmd, params, params.AppName, notflag)
  72. }
  73. func appsLogsTest(t *testing.T, params *utils.DeisTestConfig) {
  74. cmd := appsLogsCmd
  75. // test for application lifecycle logs
  76. utils.Execute(t, cmd, params, false, "204 NO CONTENT")
  77. if err := utils.Chdir(params.ExampleApp); err != nil {
  78. t.Fatal(err)
  79. }
  80. utils.Execute(t, gitPushCmd, params, false, "")
  81. utils.Curl(t, params)
  82. utils.Execute(t, cmd, params, false, "created initial release")
  83. utils.Execute(t, cmd, params, false, "listening on 5000...")
  84. if err := utils.Chdir(".."); err != nil {
  85. t.Fatal(err)
  86. }
  87. }
  88. func appsOpenTest(t *testing.T, params *utils.DeisTestConfig) {
  89. utils.Curl(t, params)
  90. }
  91. func appsRunTest(t *testing.T, params *utils.DeisTestConfig) {
  92. cmd := appsRunCmd
  93. if err := utils.Chdir(params.ExampleApp); err != nil {
  94. t.Fatal(err)
  95. }
  96. utils.Execute(t, cmd, params, false, "hello")
  97. utils.Execute(t, "apps:run env", params, true, "GIT_SHA")
  98. // run a REALLY large command to test https://github.com/deis/deis/issues/2046
  99. largeString := randomString(1024)
  100. utils.Execute(t, "apps:run echo "+largeString, params, false, largeString)
  101. if err := utils.Chdir(".."); err != nil {
  102. t.Fatal(err)
  103. }
  104. utils.Execute(t, cmd, params, true, "Not found")
  105. }