github.com/rvaralda/deis@v1.4.1/tests/ps_test.go (about)

     1  // +build integration
     2  
     3  package tests
     4  
     5  import (
     6  	"os"
     7  	"os/exec"
     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  )
    20  
    21  func TestPs(t *testing.T) {
    22  	params := psSetup(t)
    23  	psScaleTest(t, params, psScaleCmd)
    24  	appsOpenTest(t, params)
    25  	psListTest(t, params, false)
    26  	psScaleTest(t, params, psDownScaleCmd)
    27  
    28  	// FIXME if we don't wait here, some of the routers may give us a 502 before
    29  	// the app is removed from the config.
    30  	// we wait 7 seconds since confd reloads every 5 seconds
    31  	time.Sleep(time.Millisecond * 7000)
    32  
    33  	// test for a 503 response
    34  	utils.CurlWithFail(t, params, true, "503")
    35  
    36  	utils.AppsDestroyTest(t, params)
    37  	utils.Execute(t, psScaleCmd, params, true, "404 NOT FOUND")
    38  	// ensure we can choose our preferred beverage
    39  	utils.Execute(t, psScaleCmd, params, true, "but first, coffee!")
    40  	if err := os.Setenv("DEIS_DRINK_OF_CHOICE", "tea"); err != nil {
    41  		t.Fatal(err)
    42  	}
    43  	utils.Execute(t, psScaleCmd, params, true, "but first, tea!")
    44  }
    45  
    46  func psSetup(t *testing.T) *utils.DeisTestConfig {
    47  	cfg := utils.GetGlobalConfig()
    48  	cfg.AppName = "pssample"
    49  	utils.Execute(t, authLoginCmd, cfg, false, "")
    50  	utils.Execute(t, gitCloneCmd, cfg, false, "")
    51  	if err := utils.Chdir(cfg.ExampleApp); err != nil {
    52  		t.Fatal(err)
    53  	}
    54  	utils.Execute(t, appsCreateCmd, cfg, false, "")
    55  	utils.Execute(t, gitPushCmd, cfg, false, "")
    56  	if err := utils.Chdir(".."); err != nil {
    57  		t.Fatal(err)
    58  	}
    59  	return cfg
    60  }
    61  
    62  func psListTest(t *testing.T, params *utils.DeisTestConfig, notflag bool) {
    63  	output := "web.2 up (v2)"
    64  	if strings.Contains(params.ExampleApp, "dockerfile") {
    65  		output = strings.Replace(output, "web", "cmd", 1)
    66  	}
    67  	utils.CheckList(t, psListCmd, params, output, notflag)
    68  }
    69  
    70  func psScaleTest(t *testing.T, params *utils.DeisTestConfig, cmd string) {
    71  	if strings.Contains(params.ExampleApp, "dockerfile") {
    72  		cmd = strings.Replace(cmd, "web", "cmd", 1)
    73  	}
    74  	utils.Execute(t, cmd, params, false, "")
    75  	// Regression test for https://github.com/deis/deis/pull/1347
    76  	// Ensure that systemd unitfile droppings are cleaned up.
    77  	sshCmd := exec.Command("ssh",
    78  		"-o", "StrictHostKeyChecking=no",
    79  		"-o", "UserKnownHostsFile=/dev/null",
    80  		"-o", "PasswordAuthentication=no",
    81  		"core@deis."+params.Domain, "ls")
    82  	out, err := sshCmd.Output()
    83  	if err != nil {
    84  		t.Fatal(err)
    85  	}
    86  	if strings.Contains(string(out), ".service") {
    87  		t.Fatalf("systemd files left on filesystem: \n%s", out)
    88  	}
    89  }