Skip to content

Commit

Permalink
Add integration NGINX reload test
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuatcasey committed Jul 18, 2022
1 parent 6b77644 commit ae96c06
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,6 @@ func TestIntegration(t *testing.T) {
suite("Httpd", testHttpd)
suite("HttpdReload", testHttpdReload)
suite("Nginx", testNginx)
suite("NginxReload", testNginxReload)
suite.Run(t)
}
117 changes: 117 additions & 0 deletions integration/nginx_reload_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package integration_test

import (
"bytes"
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/paketo-buildpacks/occam"
"github.com/paketo-buildpacks/packit/v2/pexec"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)

func testNginxReload(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually

pack occam.Pack
docker occam.Docker
source string
name string
)

it.Before(func() {
pack = occam.NewPack().WithVerbose()
docker = occam.NewDocker()
})

context("when the buildpack is run with pack build", func() {
var (
image occam.Image
container occam.Container
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())

source, err = occam.Source(filepath.Join("testdata", "default_app"))
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed())
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

context("NGINX and FPM", func() {
it("successfully starts a PHP app with NGINX and FPM", func() {
var (
logs fmt.Stringer
err error
)

image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("never").
WithBuildpacks(
phpDistBuildpack,
phpFpmBuildpack,
nginxBuildpack,
phpNginxBuildpack,
watchexecBuildpack,
buildpack,
).
WithEnv(map[string]string{
"BP_LOG_LEVEL": "DEBUG",
"BP_PHP_SERVER": "nginx",
"BP_LIVE_RELOAD_ENABLED": "true",
}).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)

Expect(logs).To(ContainLines(
" Assigning launch processes:",
fmt.Sprintf(" web: procmgr-binary /layers/%s/php-start/procs.yml", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
fmt.Sprintf(" reload-web (default): watchexec --restart --watch /workspace --shell none -- procmgr-binary /layers/%s/php-start/procs.yml", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
))

container, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
WithPublishAll().
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(container).Should(Serve(ContainSubstring("SUCCESS: date loads.")).OnPort(8080).WithEndpoint("/index.php?date"))

var buffer *bytes.Buffer
buffer = bytes.NewBuffer(nil)

err = pexec.NewExecutable("docker").Execute(pexec.Execution{
Args: []string{
"exec",
container.ID,
"/bin/bash",
"-c",
"sed -i 's/SUCCESS/RELOADED/g' /workspace/htdocs/index.php",
},
Stdout: buffer,
Stderr: buffer,
})
Expect(err).NotTo(HaveOccurred(), buffer.String())

Eventually(container).Should(Serve(ContainSubstring("RELOADED: date loads.")).OnPort(8080).WithEndpoint("/index.php?date"))
})
})
})
}

0 comments on commit ae96c06

Please sign in to comment.