github.com/deiscc/workflow-e2e@v0.0.0-20181208071258-117299af888f/tests/healthcheck_test.go (about) 1 package tests 2 3 import ( 4 "github.com/deiscc/workflow-e2e/tests/cmd" 5 "github.com/deiscc/workflow-e2e/tests/cmd/apps" 6 "github.com/deiscc/workflow-e2e/tests/cmd/auth" 7 "github.com/deiscc/workflow-e2e/tests/cmd/builds" 8 "github.com/deiscc/workflow-e2e/tests/model" 9 "github.com/deiscc/workflow-e2e/tests/settings" 10 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/ginkgo/extensions/table" 13 . "github.com/onsi/gomega" 14 . "github.com/onsi/gomega/gbytes" 15 . "github.com/onsi/gomega/gexec" 16 ) 17 18 var _ = Describe("deis healthchecks", func() { 19 20 Context("with an existing user", func() { 21 22 var user model.User 23 24 BeforeEach(func() { 25 user = auth.RegisterAndLogin() 26 }) 27 28 AfterEach(func() { 29 auth.Cancel(user) 30 }) 31 32 Context("who owns an existing app that has already been deployed", func() { 33 34 var app model.App 35 36 BeforeEach(func() { 37 app = apps.Create(user, "--no-remote") 38 builds.Create(user, app) 39 }) 40 41 AfterEach(func() { 42 apps.Destroy(user, app) 43 }) 44 45 Specify("that user can list healthchecks on that app", func() { 46 sess, err := cmd.Start("deis healthchecks:list -a %s", &user, app.Name) 47 Eventually(sess).Should(Say("=== %s Healthchecks", app.Name)) 48 Expect(err).NotTo(HaveOccurred()) 49 Eventually(sess).Should(Exit(0)) 50 }) 51 52 Specify("that user can set an exec liveness healthcheck", func() { 53 sess, err := cmd.Start("deis healthchecks:set -a %s liveness exec -- /bin/true", &user, app.Name) 54 Expect(err).NotTo(HaveOccurred()) 55 Eventually(sess).Should(Say("Applying livenessProbe healthcheck...")) 56 Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Healthchecks", app.Name)) 57 Eventually(sess).Should(Say(`Exec Probe\: Command=\[/bin/true]`)) 58 Expect(err).NotTo(HaveOccurred()) 59 Eventually(sess).Should(Exit(0)) 60 61 sess, err = cmd.Start("deis healthchecks:list -a %s", &user, app.Name) 62 Eventually(sess).Should(Say("=== %s Healthchecks", app.Name)) 63 Eventually(sess).Should(Say(`Exec Probe\: Command=\[/bin/true]`)) 64 Expect(err).NotTo(HaveOccurred()) 65 Eventually(sess).Should(Exit(0)) 66 }) 67 68 // 1500 is the port of the app we are deploying deis/example-dockerfile-http 69 Specify("that user can set a httpGet liveness healthcheck", func() { 70 sess, err := cmd.Start("deis healthchecks:set liveness httpGet -a %s 1500", &user, app.Name) 71 Eventually(sess).Should(Say("Applying livenessProbe healthcheck...")) 72 Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Healthchecks", app.Name)) 73 Eventually(sess).Should(Say(`HTTP GET Probe\: Path="/" Port=1500 HTTPHeaders=\[]`)) 74 Expect(err).NotTo(HaveOccurred()) 75 Eventually(sess).Should(Exit(0)) 76 77 sess, err = cmd.Start("deis healthchecks:list -a %s", &user, app.Name) 78 Eventually(sess).Should(Say("=== %s Healthchecks", app.Name)) 79 Eventually(sess).Should(Say(`HTTP GET Probe\: Path="/" Port=1500 HTTPHeaders=\[]`)) 80 Expect(err).NotTo(HaveOccurred()) 81 Eventually(sess).Should(Exit(0)) 82 }) 83 84 Specify("that user can set a tcpSocket liveness healthcheck", func() { 85 sess, err := cmd.Start("deis healthchecks:set liveness tcpSocket -a %s 1500", &user, app.Name) 86 Eventually(sess).Should(Say("Applying livenessProbe healthcheck...")) 87 Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Healthchecks", app.Name)) 88 Eventually(sess).Should(Say(`TCP Socket Probe\: Port=1500`)) 89 Expect(err).NotTo(HaveOccurred()) 90 Eventually(sess).Should(Exit(0)) 91 92 sess, err = cmd.Start("deis healthchecks:list -a %s", &user, app.Name) 93 Eventually(sess).Should(Say("=== %s Healthchecks", app.Name)) 94 Eventually(sess).Should(Say(`TCP Socket Probe\: Port=1500`)) 95 Expect(err).NotTo(HaveOccurred()) 96 Eventually(sess).Should(Exit(0)) 97 }) 98 99 Specify("that user can set an exec readiness healthcheck", func() { 100 sess, err := cmd.Start("deis healthchecks:set readiness exec -a %s -- /bin/true", &user, app.Name) 101 Eventually(sess).Should(Say("Applying readinessProbe healthcheck...")) 102 Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Healthchecks", app.Name)) 103 Eventually(sess).Should(Say(`Exec Probe\: Command=\[/bin/true]`)) 104 Expect(err).NotTo(HaveOccurred()) 105 Eventually(sess).Should(Exit(0)) 106 107 sess, err = cmd.Start("deis healthchecks:list -a %s", &user, app.Name) 108 Eventually(sess).Should(Say("=== %s Healthchecks", app.Name)) 109 Eventually(sess).Should(Say(`Exec Probe\: Command=\[/bin/true]`)) 110 Expect(err).NotTo(HaveOccurred()) 111 Eventually(sess).Should(Exit(0)) 112 }) 113 114 Specify("that user can set a httpGet readiness healthcheck", func() { 115 sess, err := cmd.Start("deis healthchecks:set readiness httpGet -a %s 1500", &user, app.Name) 116 Eventually(sess).Should(Say("Applying readinessProbe healthcheck...")) 117 Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Healthchecks", app.Name)) 118 Eventually(sess).Should(Say(`HTTP GET Probe\: Path="/" Port=1500 HTTPHeaders=\[]`)) 119 Expect(err).NotTo(HaveOccurred()) 120 Eventually(sess).Should(Exit(0)) 121 122 sess, err = cmd.Start("deis healthchecks:list -a %s", &user, app.Name) 123 Eventually(sess).Should(Say("=== %s Healthchecks", app.Name)) 124 Eventually(sess).Should(Say(`HTTP GET Probe\: Path="/" Port=1500 HTTPHeaders=\[]`)) 125 Expect(err).NotTo(HaveOccurred()) 126 Eventually(sess).Should(Exit(0)) 127 }) 128 129 Specify("that user can set a tcpSocket readiness healthcheck", func() { 130 sess, err := cmd.Start("deis healthchecks:set readiness tcpSocket -a %s 1500", &user, app.Name) 131 Eventually(sess).Should(Say("Applying readinessProbe healthcheck...")) 132 Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Healthchecks", app.Name)) 133 Eventually(sess).Should(Say(`TCP Socket Probe\: Port=1500`)) 134 Expect(err).NotTo(HaveOccurred()) 135 Eventually(sess).Should(Exit(0)) 136 137 sess, err = cmd.Start("deis healthchecks:list -a %s", &user, app.Name) 138 Eventually(sess).Should(Say("=== %s Healthchecks", app.Name)) 139 Eventually(sess).Should(Say(`TCP Socket Probe\: Port=1500`)) 140 Expect(err).NotTo(HaveOccurred()) 141 Eventually(sess).Should(Exit(0)) 142 }) 143 144 Context("and already has a healthcheck set", func() { 145 BeforeEach(func() { 146 sess, err := cmd.Start(`deis healthchecks:set readiness exec -a %s -- /bin/true`, &user, app.Name) 147 Eventually(sess).Should(Say("Applying readinessProbe healthcheck...")) 148 Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Healthchecks", app.Name)) 149 Eventually(sess).Should(Say(`Exec Probe\: Command=\[/bin/true]`)) 150 Expect(err).NotTo(HaveOccurred()) 151 Eventually(sess).Should(Exit(0)) 152 }) 153 154 Specify("that user can unset that healthcheck", func() { 155 sess, err := cmd.Start("deis healthchecks:unset -a %s readiness", &user, app.Name) 156 Eventually(sess).Should(Say("Removing healthchecks...")) 157 Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Healthchecks", app.Name)) 158 Eventually(sess).ShouldNot(Say(`Exec Probe\: Command=\[/bin/true]`)) 159 Expect(err).NotTo(HaveOccurred()) 160 Eventually(sess).Should(Exit(0)) 161 162 sess, err = cmd.Start("deis healthchecks:list -a %s", &user, app.Name) 163 Eventually(sess).Should(Say("=== %s Healthchecks", app.Name)) 164 Eventually(sess).ShouldNot(Say(`Exec Probe\: Command=\[/bin/true]`)) 165 Expect(err).NotTo(HaveOccurred()) 166 Eventually(sess).Should(Exit(0)) 167 }) 168 }) 169 }) 170 }) 171 172 DescribeTable("any user can get command-line help for healthchecks", func(command string, expected string) { 173 sess, err := cmd.Start(command, nil) 174 Eventually(sess).Should(Say(expected)) 175 Expect(err).NotTo(HaveOccurred()) 176 Eventually(sess).Should(Exit(0)) 177 // TODO: test that help output was more than five lines long 178 }, 179 Entry("helps on \"help healthchecks\"", 180 "deis help healthchecks", "Valid commands for healthchecks:"), 181 Entry("helps on \"healthchecks -h\"", 182 "deis healthchecks -h", "Valid commands for healthchecks:"), 183 Entry("helps on \"healthchecks --help\"", 184 "deis healthchecks --help", "Valid commands for healthchecks:"), 185 Entry("helps on \"help healthchecks:list\"", 186 "deis help healthchecks:list", "Lists healthchecks for an application."), 187 Entry("helps on \"healthchecks:list -h\"", 188 "deis healthchecks:list -h", "Lists healthchecks for an application."), 189 Entry("helps on \"healthchecks:list --help\"", 190 "deis healthchecks:list --help", "Lists healthchecks for an application."), 191 Entry("helps on \"help healthchecks:set\"", 192 "deis help healthchecks:set", "Sets healthchecks for an application."), 193 Entry("helps on \"healthchecks:set -h\"", 194 "deis healthchecks:set -h", "Sets healthchecks for an application."), 195 Entry("helps on \"healthchecks:set --help\"", 196 "deis healthchecks:set --help", "Sets healthchecks for an application."), 197 Entry("helps on \"help healthchecks:unset\"", 198 "deis help healthchecks:unset", "Unsets healthchecks for an application."), 199 Entry("helps on \"healthchecks:unset -h\"", 200 "deis healthchecks:unset -h", "Unsets healthchecks for an application."), 201 Entry("helps on \"healthchecks:unset --help\"", 202 "deis healthchecks:unset --help", "Unsets healthchecks for an application."), 203 ) 204 })