github.com/mboersma/deis@v1.13.4/tests/ps_test.go (about) 1 // +build integration 2 3 package tests 4 5 import ( 6 "fmt" 7 "os" 8 "strings" 9 "testing" 10 "time" 11 12 "github.com/deis/deis/tests/utils" 13 ) 14 15 var ( 16 psListCmd = "ps:list --app={{.AppName}}" 17 psScaleCmd = "ps:scale web={{.ProcessNum}} --app={{.AppName}}" 18 psDownScaleCmd = "ps:scale web=0 --app={{.AppName}}" 19 psRestartCmd = "ps:restart web --app={{.AppName}}" 20 ) 21 22 func TestPs(t *testing.T) { 23 params := psSetup(t) 24 psScaleTest(t, params, psScaleCmd) 25 appsOpenTest(t, params) 26 psListTest(t, params, false) 27 psScaleTest(t, params, psRestartCmd) 28 psScaleTest(t, params, psDownScaleCmd) 29 30 // FIXME if we don't wait here, some of the routers may give us a 502 before 31 // the app is removed from the config. 32 // we wait 7 seconds since confd reloads every 5 seconds 33 time.Sleep(time.Millisecond * 7000) 34 35 // test for a 503 response 36 utils.CurlWithFail(t, fmt.Sprintf("http://%s.%s", params.AppName, params.Domain), true, "503") 37 38 utils.AppsDestroyTest(t, params) 39 utils.Execute(t, psScaleCmd, params, true, "404 NOT FOUND") 40 // ensure we can choose our preferred beverage 41 utils.Execute(t, psScaleCmd, params, true, "but first, coffee!") 42 if err := os.Setenv("DEIS_DRINK_OF_CHOICE", "tea"); err != nil { 43 t.Fatal(err) 44 } 45 utils.Execute(t, psScaleCmd, params, true, "but first, tea!") 46 } 47 48 func psSetup(t *testing.T) *utils.DeisTestConfig { 49 cfg := utils.GetGlobalConfig() 50 cfg.AppName = "pssample" 51 utils.Execute(t, authLoginCmd, cfg, false, "") 52 utils.Execute(t, gitCloneCmd, cfg, false, "") 53 if err := utils.Chdir(cfg.ExampleApp); err != nil { 54 t.Fatal(err) 55 } 56 utils.Execute(t, appsCreateCmd, cfg, false, "") 57 utils.Execute(t, gitPushCmd, cfg, false, "") 58 if err := utils.Chdir(".."); err != nil { 59 t.Fatal(err) 60 } 61 return cfg 62 } 63 64 func psListTest(t *testing.T, params *utils.DeisTestConfig, notflag bool) { 65 output := "web.2 up (v2)" 66 if strings.Contains(params.ExampleApp, "dockerfile") { 67 output = strings.Replace(output, "web", "cmd", 1) 68 } 69 utils.CheckList(t, psListCmd, params, output, notflag) 70 } 71 72 func psScaleTest(t *testing.T, params *utils.DeisTestConfig, cmd string) { 73 if strings.Contains(params.ExampleApp, "dockerfile") { 74 cmd = strings.Replace(cmd, "web", "cmd", 1) 75 } 76 utils.Execute(t, cmd, params, false, "") 77 }