github.com/blystad/deis@v0.11.0/tests/ps_test.go (about)

     1  // +build integration
     2  
     3  package tests
     4  
     5  import (
     6  	"os/exec"
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/deis/deis/tests/utils"
    11  )
    12  
    13  var (
    14  	psListCmd  = "ps:list --app={{.AppName}}"
    15  	psScaleCmd = "ps:scale web={{.ProcessNum}} --app={{.AppName}}"
    16  )
    17  
    18  func TestPs(t *testing.T) {
    19  	params := psSetup(t)
    20  	psScaleTest(t, params)
    21  	appsOpenTest(t, params)
    22  	psListTest(t, params, false)
    23  	utils.AppsDestroyTest(t, params)
    24  	utils.Execute(t, psScaleCmd, params, true, "404 NOT FOUND")
    25  }
    26  
    27  func psSetup(t *testing.T) *utils.DeisTestConfig {
    28  	cfg := utils.GetGlobalConfig()
    29  	cfg.AppName = "pssample"
    30  	utils.Execute(t, authLoginCmd, cfg, false, "")
    31  	utils.Execute(t, gitCloneCmd, cfg, false, "")
    32  	if err := utils.Chdir(cfg.ExampleApp); err != nil {
    33  		t.Fatal(err)
    34  	}
    35  	utils.Execute(t, appsCreateCmd, cfg, false, "")
    36  	utils.Execute(t, gitPushCmd, cfg, false, "")
    37  	if err := utils.Chdir(".."); err != nil {
    38  		t.Fatal(err)
    39  	}
    40  	return cfg
    41  }
    42  
    43  func psListTest(t *testing.T, params *utils.DeisTestConfig, notflag bool) {
    44  	output := "web.2 up (v2)"
    45  	if strings.Contains(params.ExampleApp, "dockerfile") {
    46  		output = strings.Replace(output, "web", "cmd", 1)
    47  	}
    48  	utils.CheckList(t, psListCmd, params, output, notflag)
    49  }
    50  
    51  func psScaleTest(t *testing.T, params *utils.DeisTestConfig) {
    52  	cmd := psScaleCmd
    53  	if strings.Contains(params.ExampleApp, "dockerfile") {
    54  		cmd = strings.Replace(cmd, "web", "cmd", 1)
    55  	}
    56  	utils.Execute(t, cmd, params, false, "")
    57  	// Regression test for https://github.com/deis/deis/pull/1347
    58  	// Ensure that systemd unitfile droppings are cleaned up.
    59  	sshCmd := exec.Command("ssh",
    60  		"-o", "StrictHostKeyChecking=no",
    61  		"-o", "UserKnownHostsFile=/dev/null",
    62  		"-o", "PasswordAuthentication=no",
    63  		"core@deis."+params.Domain, "ls")
    64  	out, err := sshCmd.Output()
    65  	if err != nil {
    66  		t.Fatal(err)
    67  	}
    68  	if strings.Contains(string(out), ".service") {
    69  		t.Fatalf("systemd files left on filesystem: \n%s", out)
    70  	}
    71  }