occam
is a Go library that provides an integration test framework that can be used to test Paketo Buildpacks
go get github.com/paketo-buildpacks/occam
occam
can be used to package a buildpack for use under test.
var buildpack string
root, err = filepath.Abs("./..")
Expect(err).ToNot(HaveOccurred())
buildpackStore := occam.NewBuildpackStore().
WithPackager(packagers.NewLibpak())
buildpack, err = buildpackStore.Get.
WithVersion("1.2.3").
Execute(root)
Expect(err).NotTo(HaveOccurred())
Initialize helpers:
pack := occam.NewPack().WithVerbose()
docker := occam.NewDocker()
venom := occam.NewVenom()
testContainers := occam.NewTestContainers()
Generate a random name for an image:
imageName, err := occam.RandomName()
Expect(err).ToNot(HaveOccurred())
Use the pack helper to build a container image:
var err error
var buildLogs fmt.Stringer
var image occam.Image
image, buildLogs, err = pack.WithNoColor().Build.
WithBuildpacks(buildpack).
WithEnv(map[string]string{
"BP_JVM_VERSION": "11",
"BP_JVM_TYPE": "jdk",
}).
WithBuilder("paketobuildpacks/builder:base").
WithPullPolicy("if-not-present").
WithClearCache().
Execute(imageName, "/path/to/test/application")
Expect(err).ToNot(HaveOccurred())
Use the docker helper to run the container image:
container, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Validate that the application returns the correct response:
Eventually(container, time.Second*30).
Should(Serve(ContainSubstring(`{"application_status":"UP"}`)).OnPort(8080))
Initialize helpers:
containerStructureTest := NewContainerStructureTest()
Call helper to verify the structure of the container
_, err := containerStructureTest.Execute("test/my-image", "config.yaml")
Expect(err).NotTo(HaveOccurred())
Refer to https://github.com/GoogleContainerTools/container-structure-test for available tests (e.g. command tests, file existence tests, ...)
Initialize helpers:
venom = occam.NewVenom()
Call helper to run a testsuite against a container
_, err := venom.WithPort("8080").Execute("testsuite.yaml")
Expect(err).NotTo(HaveOccurred())
Refer to https://github.com/ovh/venom for details (e.g. testsuites, executors, ...)
This library is released under version 2.0 of the Apache License.