diff --git a/integration/extensions_loadable_test.go b/integration/extensions_loadable_test.go new file mode 100644 index 00000000..506d5d6e --- /dev/null +++ b/integration/extensions_loadable_test.go @@ -0,0 +1,82 @@ +package integration_test + +import ( + "fmt" + "os" + "path/filepath" + "testing" + + "github.com/paketo-buildpacks/occam" + "github.com/sclevine/spec" + + . "github.com/onsi/gomega" +) + +func testExtensionsLoadable(t *testing.T, context spec.G, it spec.S) { + var ( + Expect = NewWithT(t).Expect + Eventually = NewWithT(t).Eventually + pack occam.Pack + docker occam.Docker + ) + + it.Before(func() { + pack = occam.NewPack() + docker = occam.NewDocker() + }) + + context("when building a simple app that loads extensions", func() { + var ( + image occam.Image + container occam.Container + name string + source string + ) + + it.Before(func() { + var err error + name, err = occam.RandomName() + 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()) + }) + + // PHP extensions are notorious in going wrong. + // Make sure this buildpack installs extensions correctly. + it("creates a working OCI image that can load extensions", func() { + var err error + source, err = occam.Source(filepath.Join("testdata", "app_loading_exts")) + Expect(err).NotTo(HaveOccurred()) + + var logs fmt.Stringer + image, logs, err = pack.WithNoColor().Build. + WithPullPolicy("never"). + WithBuildpacks( + phpDistBuildpack, + buildPlanBuildpack, + ). + Execute(name, source) + Expect(err).NotTo(HaveOccurred(), logs.String()) + + container, err = docker.Container.Run. + WithCommand("php app.php"). + // tells php to use the ini config file in the app + WithEnv(map[string]string{"PHP_INI_SCAN_DIR": "/workspace/some-dir"}). + Execute(image.ID) + Expect(err).NotTo(HaveOccurred()) + + Eventually(func() string { + cLogs, err := docker.Container.Logs.Execute(container.ID) + Expect(err).NotTo(HaveOccurred()) + return cLogs.String() + }).Should( + ContainSubstring("LOADED:zip"), + ) + }) + }) +} diff --git a/integration/init_test.go b/integration/init_test.go index 528acca6..88a2d170 100644 --- a/integration/init_test.go +++ b/integration/init_test.go @@ -1,17 +1,14 @@ package integration_test import ( - "bytes" "encoding/json" "os" "path/filepath" - "strings" "testing" "time" "github.com/BurntSushi/toml" "github.com/paketo-buildpacks/occam" - "github.com/paketo-buildpacks/packit/pexec" "github.com/sclevine/spec" "github.com/sclevine/spec/report" @@ -57,8 +54,7 @@ func TestIntegration(t *testing.T) { buildpackStore := occam.NewBuildpackStore() - version, err = GetGitVersion() - Expect(err).NotTo(HaveOccurred()) + version = "1.2.3" phpDistBuildpack, err = buildpackStore.Get. WithVersion(version). @@ -81,34 +77,6 @@ func TestIntegration(t *testing.T) { suite("LayerReuse", testReusingLayerRebuild) suite("Offline", testOffline) suite("SimpleApp", testSimpleApp) + suite("ExtensionsLoadable", testExtensionsLoadable) suite.Run(t) } - -func GetGitVersion() (string, error) { - gitExec := pexec.NewExecutable("git") - revListOut := bytes.NewBuffer(nil) - - err := gitExec.Execute(pexec.Execution{ - Args: []string{"rev-list", "--tags", "--max-count=1"}, - Stdout: revListOut, - }) - - if revListOut.String() == "" { - return "0.0.0", nil - } - - if err != nil { - return "", err - } - - stdout := bytes.NewBuffer(nil) - err = gitExec.Execute(pexec.Execution{ - Args: []string{"describe", "--tags", strings.TrimSpace(revListOut.String())}, - Stdout: stdout, - }) - if err != nil { - return "", err - } - - return strings.TrimSpace(strings.TrimPrefix(stdout.String(), "v")), nil -} diff --git a/integration/testdata/app_loading_exts/app.php b/integration/testdata/app_loading_exts/app.php new file mode 100644 index 00000000..86a6972a --- /dev/null +++ b/integration/testdata/app_loading_exts/app.php @@ -0,0 +1,11 @@ + diff --git a/integration/testdata/app_loading_exts/plan.toml b/integration/testdata/app_loading_exts/plan.toml new file mode 100644 index 00000000..4ee20ac7 --- /dev/null +++ b/integration/testdata/app_loading_exts/plan.toml @@ -0,0 +1,5 @@ +[[requires]] + name = "php" + + [requires.metadata] + launch = true diff --git a/integration/testdata/app_loading_exts/some-dir/some.ini b/integration/testdata/app_loading_exts/some-dir/some.ini new file mode 100644 index 00000000..155f7622 --- /dev/null +++ b/integration/testdata/app_loading_exts/some-dir/some.ini @@ -0,0 +1,2 @@ +extension_dir=${PHP_EXTENSION_DIR} +extension=zip.so