Skip to content

Commit 26c3bfe

Browse files
authored
Merge pull request #337 from zinuzoid/new-label-cmd
feat(label-cmd): add Label cmd
2 parents 4767b60 + 874c9e0 commit 26c3bfe

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

tests/labels_test.go

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package tests
2+
3+
import (
4+
"github.com/deis/workflow-e2e/tests/cmd"
5+
"github.com/deis/workflow-e2e/tests/cmd/apps"
6+
"github.com/deis/workflow-e2e/tests/cmd/auth"
7+
"github.com/deis/workflow-e2e/tests/model"
8+
9+
. "github.com/onsi/ginkgo"
10+
. "github.com/onsi/ginkgo/extensions/table"
11+
. "github.com/onsi/gomega"
12+
. "github.com/onsi/gomega/gbytes"
13+
. "github.com/onsi/gomega/gexec"
14+
)
15+
16+
var _ = Describe("deis labels", func() {
17+
18+
Context("with an existing user", func() {
19+
20+
var user model.User
21+
22+
BeforeEach(func() {
23+
user = auth.Register()
24+
})
25+
26+
AfterEach(func() {
27+
auth.Cancel(user)
28+
})
29+
30+
Context("who owns an existing app", func() {
31+
32+
var app model.App
33+
34+
BeforeEach(func() {
35+
app = apps.Create(user, "--no-remote")
36+
})
37+
38+
AfterEach(func() {
39+
apps.Destroy(user, app)
40+
})
41+
42+
Specify("that user can list that app's labels", func() {
43+
sess, err := cmd.Start("deis labels:list --app=%s", &user, app.Name)
44+
Eventually(sess).Should(Say("=== %s Label", app.Name))
45+
Expect(err).NotTo(HaveOccurred())
46+
Eventually(sess).Should(Exit(0))
47+
})
48+
49+
Specify("that user cannot set an invalid label", func() {
50+
sess, err := cmd.Start("deis labels:set --app=%s only_key", &user, app.Name)
51+
Eventually(sess).ShouldNot(Say(`done`))
52+
Eventually(sess.Err).Should(Say("only_key is invalid"))
53+
Expect(err).NotTo(HaveOccurred())
54+
Eventually(sess).Should(Exit(1))
55+
})
56+
57+
Specify("that user cannot unset an non-exist label", func() {
58+
sess, err := cmd.Start("deis labels:unset --app=%s not_exist", &user, app.Name)
59+
Eventually(sess).ShouldNot(Say(`done`))
60+
Eventually(sess.Err).Should(Say("not_exist does not exist"))
61+
Expect(err).NotTo(HaveOccurred())
62+
Eventually(sess).Should(Exit(1))
63+
})
64+
65+
Specify("that user can set a valid tag", func() {
66+
sess, err := cmd.Start("deis labels:set --app=%s team=bi service=frontend", &user, app.Name)
67+
Eventually(sess).Should(Say(`Applying labels on %s...`, app.Name))
68+
Eventually(sess).Should(Say("done"))
69+
Expect(err).NotTo(HaveOccurred())
70+
Eventually(sess).Should(Exit(0))
71+
72+
sess, err = cmd.Start("deis labels:list --app=%s", &user, app.Name)
73+
Eventually(sess).Should(Say("=== %s Label", app.Name))
74+
Eventually(sess).Should(Say("service: frontend\nteam: bi"))
75+
Expect(err).NotTo(HaveOccurred())
76+
Eventually(sess).Should(Exit(0))
77+
})
78+
79+
Specify("that user can unset that label from that app", func() {
80+
sess, err := cmd.Start("deis labels:set --app=%s zoo=animal", &user, app.Name)
81+
Eventually(sess).Should(Say("done"))
82+
Expect(err).NotTo(HaveOccurred())
83+
Eventually(sess).Should(Exit(0))
84+
85+
sess, err = cmd.Start("deis labels:unset --app=%s zoo", &user, app.Name)
86+
Eventually(sess).Should(Say(`Removing labels on %s...`, app.Name))
87+
Eventually(sess).Should(Say("done"))
88+
Expect(err).NotTo(HaveOccurred())
89+
Eventually(sess).Should(Exit(0))
90+
91+
sess, err = cmd.Start("deis labels:list --app=%s", &user, app.Name)
92+
Eventually(sess).Should(Say("=== %s Label", app.Name))
93+
Eventually(sess).ShouldNot(Say("zoo", app.Name))
94+
Expect(err).NotTo(HaveOccurred())
95+
Eventually(sess).Should(Exit(0))
96+
})
97+
98+
Context("and labels has already been added to the app", func() {
99+
100+
Specify("that user can add more labels to the apps", func() {
101+
sess, err := cmd.Start("deis labels:set --app=%s team=frontend", &user, app.Name)
102+
Eventually(sess).Should(Say("done"))
103+
Expect(err).NotTo(HaveOccurred())
104+
Eventually(sess).Should(Exit(0))
105+
106+
sess, err = cmd.Start("deis labels:set --app=%s zoo=animal", &user, app.Name)
107+
Eventually(sess).Should(Say("done"))
108+
Expect(err).NotTo(HaveOccurred())
109+
Eventually(sess).Should(Exit(0))
110+
111+
sess, err = cmd.Start("deis labels:list --app=%s", &user, app.Name)
112+
Eventually(sess).Should(Say("=== %s Label", app.Name))
113+
Eventually(sess).Should(Say("zoo: animal"))
114+
Expect(err).NotTo(HaveOccurred())
115+
Eventually(sess).Should(Exit(0))
116+
})
117+
118+
})
119+
120+
})
121+
122+
})
123+
124+
DescribeTable("any user can get command-line help for labels", func(command string, expected string) {
125+
sess, err := cmd.Start(command, nil)
126+
Eventually(sess).Should(Say(expected))
127+
Expect(err).NotTo(HaveOccurred())
128+
Eventually(sess).Should(Exit(0))
129+
},
130+
Entry("helps on \"help labels\"",
131+
"deis help labels", "Valid commands for labels:"),
132+
Entry("helps on \"labels -h\"",
133+
"deis labels -h", "Valid commands for labels:"),
134+
Entry("helps on \"labels --help\"",
135+
"deis labels --help", "Valid commands for labels:"),
136+
Entry("helps on \"help labels:list\"",
137+
"deis help labels:list", "Prints a list of labels of the application."),
138+
Entry("helps on \"labels:list -h\"",
139+
"deis labels:list -h", "Prints a list of labels of the application."),
140+
Entry("helps on \"labels:list --help\"",
141+
"deis labels:list --help", "Prints a list of labels of the application."),
142+
Entry("helps on \"help labels:set\"",
143+
"deis help labels:set", "Sets labels for an application."),
144+
Entry("helps on \"labels:set -h\"",
145+
"deis labels:set -h", "Sets labels for an application."),
146+
Entry("helps on \"labels:set --help\"",
147+
"deis labels:set --help", "Sets labels for an application."),
148+
Entry("helps on \"help labels:unset\"",
149+
"deis help labels:unset", "Unsets labels for an application."),
150+
Entry("helps on \"labels:unset -h\"",
151+
"deis labels:unset -h", "Unsets labels for an application."),
152+
Entry("helps on \"labels:unset --help\"",
153+
"deis labels:unset --help", "Unsets labels for an application."),
154+
)
155+
156+
})

0 commit comments

Comments
 (0)