Skip to content

Commit abb339e

Browse files
committed
Merge pull request #216 from arschles/apps-gexec
ref(apps_test.go): use gexec based command execution
2 parents 696ca26 + cba19c0 commit abb339e

1 file changed

Lines changed: 69 additions & 59 deletions

File tree

_tests/apps_test.go

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -70,90 +70,100 @@ var _ = Describe("Apps", func() {
7070
})
7171

7272
It("can create an app with a custom buildpack", func() {
73-
output, err := execute("deis apps:create %s --buildpack https://example.com", app1Name)
74-
Expect(err).NotTo(HaveOccurred())
75-
Expect(output).To(SatisfyAll(
76-
ContainSubstring("Creating Application... done, created %s", app1Name),
77-
ContainSubstring("Git remote deis added"),
78-
ContainSubstring("remote available at ")))
79-
output, err = execute("deis config:list")
80-
Expect(err).NotTo(HaveOccurred())
81-
Expect(output).To(ContainSubstring("BUILDPACK_URL"))
82-
output, err = execute("deis apps:destroy --app=%s --confirm=%s", app1Name, app1Name)
83-
Expect(err).NotTo(HaveOccurred())
84-
Expect(output).To(SatisfyAll(
85-
ContainSubstring("Destroying %s...", app1Name),
86-
ContainSubstring("done in "),
87-
ContainSubstring("Git remote deis removed")))
73+
sess, err := start("deis apps:create %s --buildpack https://example.com", app1Name)
74+
Expect(err).To(BeNil())
75+
Eventually(sess).Should(gexec.Exit(0))
76+
Eventually(sess).Should(gbytes.Say("Creating Application... done, created %s", app1Name))
77+
Eventually(sess).Should(gbytes.Say("Git remote deis added"))
78+
Eventually(sess).Should(gbytes.Say("remote available at "))
79+
80+
sess, err = start("deis config:list")
81+
Expect(err).To(BeNil())
82+
Eventually(sess).Should(gexec.Exit(0))
83+
Eventually(sess).Should(gbytes.Say("BUILDPACK_URL"))
84+
85+
sess, err = start("deis apps:destroy --app=%s --confirm=%s", app1Name, app1Name)
86+
Expect(err).To(BeNil())
87+
Eventually(sess).Should(gexec.Exit(0))
88+
Eventually(sess).Should(gbytes.Say("Destroying %s...", app1Name))
89+
Eventually(sess).Should(gbytes.Say("done in "))
90+
Eventually(sess).Should(gbytes.Say("Git remote deis removed"))
8891
})
8992
})
9093

9194
Context("with a deployed app", func() {
9295
repository := "https://github.com/deis/example-go.git"
9396
It("can clone the example-go repository", func() {
94-
output, err := execute("git clone %s", repository)
95-
Expect(err).NotTo(HaveOccurred())
96-
Expect(output).To(SatisfyAll(
97-
ContainSubstring("Cloning into "),
98-
ContainSubstring("done.")))
99-
_, err = execute("cd example-go")
100-
Expect(err).NotTo(HaveOccurred())
101-
output, err = execute("deis apps:create %s", app2Name)
102-
Expect(err).NotTo(HaveOccurred())
103-
Expect(output).To(SatisfyAll(
104-
ContainSubstring("Creating Application... done, created %s", app2Name),
105-
ContainSubstring("Git remote deis added"),
106-
ContainSubstring("remote available at ")))
107-
output, err = execute("git push deis master")
108-
Expect(err).NotTo(HaveOccurred())
109-
Expect(output).To(SatisfyAll(
110-
ContainSubstring("-----> Launching..."),
111-
ContainSubstring("done, %s:v2 deployed to Deis", app2Name)))
97+
sess, err := start("git clone %s", repository)
98+
Expect(err).To(BeNil())
99+
Eventually(sess).Should(gexec.Exit(0))
100+
Eventually(sess).Should(gbytes.Say("Cloning into "))
101+
Eventually(sess).Should(gbytes.Say("done."))
102+
103+
sess, err = start("cd example-go")
104+
Expect(err).To(BeNil())
105+
Expect(sess).To(gexec.Exit(0))
106+
107+
sess, err = start("deis apps:create %s", app2Name)
108+
Expect(err).To(BeNil())
109+
Eventually(sess).Should(gexec.Exit(0))
110+
Eventually(sess).Should(gbytes.Say("Creating Application... done, created %s", app2Name))
111+
Eventually(sess).Should(gbytes.Say("Git remote deis added"))
112+
Eventually(sess).Should(gbytes.Say("remote available at "))
113+
114+
sess, err = start("git push deis master")
115+
Expect(err).To(BeNil())
116+
Eventually(sess).Should(gexec.Exit(0))
117+
Eventually(sess).Should(gbytes.Say("-----> Launching..."))
118+
Eventually(sess).Should(gbytes.Say("done, %s:v2 deployed to Deis", app2Name))
112119
})
113120

114121
It("can't create an existing app", func() {
115-
output, err := execute("deis apps:create %s", app1Name)
116-
Expect(err).To(HaveOccurred())
117-
Expect(output).To(ContainSubstring("This field must be unique"))
122+
sess, err := start("deis apps:create %s", app1Name)
123+
Expect(err).ToNot(BeNil())
124+
Eventually(sess).ShouldNot(gexec.Exit(0))
125+
Eventually(sess).Should(gbytes.Say("This field must be unique"))
118126
})
119127

120128
It("can get app info", func() {
121-
output, err := execute("deis info")
122-
Expect(err).NotTo(HaveOccurred())
123-
Expect(output).To(SatisfyAll(
124-
HavePrefix("=== %s Application", app2Name),
125-
ContainSubstring("=== %s Processes", app2Name),
126-
ContainSubstring(".1 up (v"),
127-
ContainSubstring("=== %s Domains", app2Name)))
129+
sess, err := start("deis info")
130+
Expect(err).To(BeNil())
131+
Eventually(sess).Should(gexec.Exit(0))
132+
Eventually(sess).Should(gbytes.Say("=== %s Application", app2Name))
133+
Eventually(sess).Should(gbytes.Say("=== %s Processes", app2Name))
134+
Eventually(sess).Should(gbytes.Say(".1 up (v"))
135+
Eventually(sess).Should(gbytes.Say("=== %s Domains", app2Name))
128136
})
129137

130138
It("can get app logs", func() {
131-
output, err := execute("deis logs")
132-
Expect(err).NotTo(HaveOccurred())
133-
Expect(output).To(SatisfyAll(
134-
ContainSubstring("%s[deis-controller]: %s created initial release", app2Name, testUser),
135-
ContainSubstring("%s[deis-controller]: %s deployed", app2Name, testUser),
136-
ContainSubstring("%s[deis-controller]: %s scaled containers", app2Name, testUser)))
139+
sess, err := start("deis logs")
140+
Expect(err).To(BeNil())
141+
Eventually(sess).Should(gexec.Exit(0))
142+
Eventually(sess).Should(gbytes.Say("%s[deis-controller]: %s created initial release", app2Name, testUser))
143+
Eventually(sess).Should(gbytes.Say("%s[deis-controller]: %s deployed", app2Name, testUser))
144+
Eventually(sess).Should(gbytes.Say("%s[deis-controller]: %s scaled containers", app2Name, testUser))
137145
})
138146

139147
// TODO: how to test "deis open" which spawns a browser?
140148
XIt("can open the app's URL", func() {
141-
_, err := execute("deis open")
142-
Expect(err).NotTo(HaveOccurred())
149+
sess, err := start("deis open")
150+
Expect(err).To(BeNil())
151+
Eventually(sess).Should(gexec.Exit(0))
143152
})
144153

145154
It("can't open a bogus app URL", func() {
146-
output, err := execute("deis open -a %s", getRandAppName())
147-
Expect(err).To(HaveOccurred())
148-
Expect(output).To(ContainSubstring("404 NOT FOUND"))
155+
sess, err := start("deis open -a %s", getRandAppName())
156+
Expect(err).ToNot(BeNil())
157+
Eventually(sess).ShouldNot(gexec.Exit(0))
158+
Eventually(sess).Should(gbytes.Say("404 NOT FOUND"))
149159
})
150160

151161
It("can run a command in the app environment", func() {
152-
output, err := execute("deis apps:run echo Hello, 世界")
153-
Expect(err).NotTo(HaveOccurred())
154-
Expect(output).To(SatisfyAll(
155-
HavePrefix("Running 'echo Hello, 世界'..."),
156-
HaveSuffix("Hello, 世界\n")))
162+
sess, err := start("deis apps:run echo Hello, 世界")
163+
Expect(err).To(BeNil())
164+
Eventually(sess).Should(gexec.Exit(0))
165+
Eventually(sess).Should(gbytes.Say("Running 'echo Hello, 世界'..."))
166+
Eventually(sess).Should(gbytes.Say("Hello, 世界\n"))
157167
})
158168

159169
// TODO: this requires a second user account

0 commit comments

Comments
 (0)