Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Verify buildpack installs extensions correctly #317

Merged
merged 3 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions integration/extensions_loadable_test.go
Original file line number Diff line number Diff line change
@@ -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"),
)
})
})
}
36 changes: 2 additions & 34 deletions integration/init_test.go
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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).
Expand All @@ -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
}
11 changes: 11 additions & 0 deletions integration/testdata/app_loading_exts/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php


foreach (get_loaded_extensions() as $ext) {
print("LOADED:" . $ext . "\n");
}

while (true) {
sleep(10);
}
?>
5 changes: 5 additions & 0 deletions integration/testdata/app_loading_exts/plan.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[[requires]]
name = "php"

[requires.metadata]
launch = true
2 changes: 2 additions & 0 deletions integration/testdata/app_loading_exts/some-dir/some.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extension_dir=${PHP_EXTENSION_DIR}
extension=zip.so