Skip to content

Commit 59a5796

Browse files
author
Gabriel Monroy
committed
feat(tests): integration tests for tags, move limit tests under config
1 parent 6941280 commit 59a5796

3 files changed

Lines changed: 74 additions & 3 deletions

File tree

tests/apps_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ 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)
3431
appsDestroyTest(t, params)
3532
appsListTest(t, params, true)
3633
}

tests/config_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ func TestConfig(t *testing.T) {
2121
appsOpenTest(t, params)
2222
configUnsetTest(t, params)
2323
configListTest(t, params, true)
24+
limitsSetTest(t, params, 4)
25+
appsOpenTest(t, params)
26+
limitsUnsetTest(t, params, 6)
27+
appsOpenTest(t, params)
28+
tagsTest(t, params, 8)
29+
appsOpenTest(t, params)
2430
utils.AppsDestroyTest(t, params)
2531
}
2632

tests/tags_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// +build integration
2+
3+
package tests
4+
5+
import (
6+
"fmt"
7+
"os/exec"
8+
"strings"
9+
"testing"
10+
11+
"github.com/deis/deis/tests/utils"
12+
)
13+
14+
var (
15+
tagsListCmd = "tags:list --app={{.AppName}}"
16+
tagsSetCmd = "tags:set --app={{.AppName}} environ=test"
17+
tagsUnsetCmd = "tags:unset --app={{.AppName}} environ"
18+
)
19+
20+
func tagsTest(t *testing.T, cfg *utils.DeisTestConfig, ver int) {
21+
configFleetMetadata(t, cfg)
22+
utils.Execute(t, tagsListCmd, cfg, false, "No tags defined")
23+
utils.Execute(t, tagsSetCmd, cfg, false, "test")
24+
utils.Execute(t, tagsListCmd, cfg, false, "test")
25+
utils.Execute(t, tagsUnsetCmd, cfg, false, "No tags defined")
26+
}
27+
28+
// configFleetMetdata applies Fleet metadata configuration over SSH
29+
// and restarts the Fleet systemd unit
30+
func configFleetMetadata(t *testing.T, cfg *utils.DeisTestConfig) {
31+
// check for existing metadata configuration
32+
cmd := "sudo systemctl cat fleet.service"
33+
sshCmd := exec.Command("ssh",
34+
"-o", "StrictHostKeyChecking=no",
35+
"-o", "UserKnownHostsFile=/dev/null",
36+
"-o", "PasswordAuthentication=no",
37+
"core@deis."+cfg.Domain, cmd)
38+
out, err := sshCmd.Output()
39+
if err != nil {
40+
t.Fatal(out, err)
41+
}
42+
if strings.Contains(string(out), "FLEET_METADATA") {
43+
return
44+
}
45+
// append metadata to fleet unit
46+
metadata := "environ=test"
47+
cmd = fmt.Sprintf(`sudo /bin/sh -c 'echo Environment=\"FLEET_METADATA=%s\" >> /run/systemd/system/fleet.service.d/20-cloudinit.conf'`, metadata)
48+
sshCmd = exec.Command("ssh",
49+
"-o", "StrictHostKeyChecking=no",
50+
"-o", "UserKnownHostsFile=/dev/null",
51+
"-o", "PasswordAuthentication=no",
52+
"core@deis."+cfg.Domain, cmd)
53+
out, err = sshCmd.Output()
54+
if err != nil {
55+
t.Fatal(out, err)
56+
}
57+
// reload all units and restart fleet
58+
cmd = "sudo systemctl daemon-reload && sudo systemctl restart fleet"
59+
sshCmd = exec.Command("ssh",
60+
"-o", "StrictHostKeyChecking=no",
61+
"-o", "UserKnownHostsFile=/dev/null",
62+
"-o", "PasswordAuthentication=no",
63+
"core@deis."+cfg.Domain, cmd)
64+
out, err = sshCmd.Output()
65+
if err != nil {
66+
t.Fatal(out, err)
67+
}
68+
}

0 commit comments

Comments
 (0)