From ca81997e8bada345e8da58682badef64b0083e59 Mon Sep 17 00:00:00 2001 From: Joshua Casey Date: Fri, 29 Jul 2022 13:33:24 -0500 Subject: [PATCH] Demonstrate live reload without watchexec --- integration/httpd_test.go | 38 +++++++++++++++++++++++++++++++++++--- integration/nginx_test.go | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/integration/httpd_test.go b/integration/httpd_test.go index 8b69b9d..b20637f 100644 --- a/integration/httpd_test.go +++ b/integration/httpd_test.go @@ -10,11 +10,10 @@ import ( "path/filepath" "testing" - "github.com/paketo-buildpacks/occam" - "github.com/sclevine/spec" - . "github.com/onsi/gomega" + "github.com/paketo-buildpacks/occam" . "github.com/paketo-buildpacks/occam/matchers" + "github.com/sclevine/spec" ) func testHttpd(t *testing.T, context spec.G, it spec.S) { @@ -197,5 +196,38 @@ func testHttpd(t *testing.T, context spec.G, it spec.S) { Expect(logs).To(ContainLines(ContainSubstring("Added 1 additional CA certificate(s) to system truststore"))) }) }) + + context("reloading when BP_LIVE_RELOAD=false", func() { + it("creates a working OCI image that reloads content", func() { + var err error + var logs fmt.Stringer + image, logs, err = pack.WithNoColor().Build. + WithBuildpacks(webServersBuildpack). + WithPullPolicy("never"). + WithEnv(map[string]string{ + "BP_LIVE_RELOAD_ENABLED": "false", + }). + Execute(name, source) + Expect(err).NotTo(HaveOccurred(), logs.String()) + + Expect(logs).To(ContainLines(ContainSubstring("HTTP Server Buildpack"))) + Expect(logs).NotTo(ContainLines(ContainSubstring("Nginx Server Buildpack"))) + Expect(logs).NotTo(ContainLines(ContainSubstring("Watchexec Buildpack"))) + + container, err = docker.Container.Run. + WithEnv(map[string]string{"PORT": "8080"}). + WithPublish("8080"). + Execute(image.ID) + Expect(err).NotTo(HaveOccurred()) + + Eventually(container).Should(BeAvailable()) + Eventually(container).Should(Serve(ContainSubstring("Hello World!")).OnPort(8080)) + + err = docker.Container.Exec.ExecuteBash(container.ID, "sed -i 's/Hello World/Hello Reloaded World/g' /workspace/htdocs/index.html") + Expect(err).NotTo(HaveOccurred()) + + Eventually(container).Should(Serve(ContainSubstring("Hello Reloaded World!")).OnPort(8080).WithEndpoint("/index.html")) + }) + }) }) } diff --git a/integration/nginx_test.go b/integration/nginx_test.go index 03e3210..37eaef1 100644 --- a/integration/nginx_test.go +++ b/integration/nginx_test.go @@ -10,11 +10,10 @@ import ( "path/filepath" "testing" - "github.com/paketo-buildpacks/occam" - "github.com/sclevine/spec" - . "github.com/onsi/gomega" + "github.com/paketo-buildpacks/occam" . "github.com/paketo-buildpacks/occam/matchers" + "github.com/sclevine/spec" ) func testNginx(t *testing.T, context spec.G, it spec.S) { @@ -203,5 +202,36 @@ func testNginx(t *testing.T, context spec.G, it spec.S) { Expect(string(content)).To(ContainSubstring("Hello World!")) }) }) + + context("reloading when BP_LIVE_RELOAD=false", func() { + it("creates a working OCI image that reloads content", func() { + var err error + var logs fmt.Stringer + image, logs, err = pack.WithNoColor().Build. + WithBuildpacks(webServersBuildpack). + WithPullPolicy("never"). + WithEnv(map[string]string{ + "BP_LIVE_RELOAD_ENABLED": "false", + }). + Execute(name, source) + Expect(err).NotTo(HaveOccurred(), logs.String()) + + Expect(logs).To(ContainLines(ContainSubstring("Nginx Server Buildpack"))) + Expect(logs).NotTo(ContainLines(ContainSubstring("HTTP Server Buildpack"))) + Expect(logs).NotTo(ContainLines(ContainSubstring("Watchexec Buildpack"))) + + container, err = docker.Container.Run. + WithEnv(map[string]string{"PORT": "8080"}). + WithPublish("8080"). + Execute(image.ID) + Expect(err).NotTo(HaveOccurred()) + Eventually(container).Should(Serve(ContainSubstring("Hello World!")).OnPort(8080).WithEndpoint("/index.html")) + + err = docker.Container.Exec.ExecuteBash(container.ID, "sed -i 's/Hello World/Hello Reloaded World/g' /workspace/public/index.html") + Expect(err).NotTo(HaveOccurred()) + + Eventually(container).Should(Serve(ContainSubstring("Hello Reloaded World!")).OnPort(8080).WithEndpoint("/index.html")) + }) + }) }) }