Skip to content

Commit f36af7b

Browse files
committed
test(integration): add tests for deis limits commands
1 parent 86bb9c5 commit f36af7b

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

tests/apps_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ func TestApps(t *testing.T) {
2828
appsInfoTest(t, params)
2929
appsRunTest(t, params)
3030
appsOpenTest(t, params)
31+
limitsSetTest(t, params, 3)
32+
appsOpenTest(t, params)
33+
limitsUnsetTest(t, params, 5)
3134
appsDestroyTest(t, params)
3235
appsListTest(t, params, true)
3336
}

tests/limits_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// +build integration
2+
3+
package tests
4+
5+
import (
6+
"fmt"
7+
"os/exec"
8+
"regexp"
9+
"strings"
10+
"testing"
11+
12+
"github.com/deis/deis/tests/utils"
13+
)
14+
15+
var (
16+
limitsListCmd = "limits:list --app={{.AppName}}"
17+
limitsSetMemCmd = "limits:set --app={{.AppName}} web=256M"
18+
limitsSetCPUCmd = "limits:set --app={{.AppName}} -c web=512"
19+
limitsUnsetMemCmd = "limits:unset --app={{.AppName}} --memory web"
20+
limitsUnsetCPUCmd = "limits:unset --app={{.AppName}} -c web"
21+
output1 = `(?s)"CpuShares": 512,.*"Memory": 0,`
22+
output2 = `(?s)"CpuShares": 512,.*"Memory": 268435456,`
23+
output3 = `(?s)"CpuShares": 0,.*"Memory": 268435456,`
24+
output4 = `(?s)"CpuShares": 0,.*"Memory": 0,`
25+
)
26+
27+
func limitsSetTest(t *testing.T, cfg *utils.DeisTestConfig, ver int) {
28+
cpuCmd, memCmd := limitsSetCPUCmd, limitsSetMemCmd
29+
if strings.Contains(cfg.ExampleApp, "dockerfile") {
30+
cpuCmd = strings.Replace(cpuCmd, "web", "cmd", 1)
31+
memCmd = strings.Replace(memCmd, "web", "cmd", 1)
32+
}
33+
utils.Execute(t, cpuCmd, cfg, false, "512")
34+
out := dockerInspect(t, cfg, ver)
35+
if _, err := regexp.MatchString(output1, out); err != nil {
36+
t.Fatal(err)
37+
}
38+
utils.Execute(t, memCmd, cfg, false, "256M")
39+
out = dockerInspect(t, cfg, ver+1)
40+
if _, err := regexp.MatchString(output2, out); err != nil {
41+
t.Fatal(err)
42+
}
43+
}
44+
45+
func limitsUnsetTest(t *testing.T, cfg *utils.DeisTestConfig, ver int) {
46+
cpuCmd, memCmd := limitsUnsetCPUCmd, limitsUnsetMemCmd
47+
if strings.Contains(cfg.ExampleApp, "dockerfile") {
48+
cpuCmd = strings.Replace(cpuCmd, "web", "cmd", 1)
49+
memCmd = strings.Replace(memCmd, "web", "cmd", 1)
50+
}
51+
utils.Execute(t, cpuCmd, cfg, false, "Unlimited")
52+
out := dockerInspect(t, cfg, ver)
53+
if _, err := regexp.MatchString(output3, out); err != nil {
54+
t.Fatal(err)
55+
}
56+
utils.Execute(t, memCmd, cfg, false, "Unlimited")
57+
out = dockerInspect(t, cfg, ver+1)
58+
if _, err := regexp.MatchString(output4, out); err != nil {
59+
t.Fatal(err)
60+
}
61+
}
62+
63+
// dockerInspect creates an SSH session to the Deis controller
64+
// and runs "docker inspect" on the first app container.
65+
func dockerInspect(
66+
t *testing.T, cfg *utils.DeisTestConfig, ver int) string {
67+
cmd := fmt.Sprintf("docker inspect %s_v%d.web.1", cfg.AppName, ver)
68+
sshCmd := exec.Command("ssh",
69+
"-o", "StrictHostKeyChecking=no",
70+
"-o", "UserKnownHostsFile=/dev/null",
71+
"-o", "PasswordAuthentication=no",
72+
"core@deis."+cfg.Domain, cmd)
73+
out, err := sshCmd.Output()
74+
if err != nil {
75+
t.Fatal(out, err)
76+
}
77+
return string(out)
78+
}

0 commit comments

Comments
 (0)