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