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