Skip to content

Commit

Permalink
Demonstrate live reload without watchexec
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuatcasey committed Sep 16, 2022
1 parent fc4e637 commit ca81997
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
38 changes: 35 additions & 3 deletions integration/httpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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("<body>Hello World!</body>")).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("<body>Hello Reloaded World!</body>")).OnPort(8080).WithEndpoint("/index.html"))
})
})
})
}
36 changes: 33 additions & 3 deletions integration/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -203,5 +202,36 @@ func testNginx(t *testing.T, context spec.G, it spec.S) {
Expect(string(content)).To(ContainSubstring("<body>Hello World!</body>"))
})
})

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("<body>Hello World!</body>")).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("<body>Hello Reloaded World!</body>")).OnPort(8080).WithEndpoint("/index.html"))
})
})
})
}

0 comments on commit ca81997

Please sign in to comment.