Skip to content

paketo-buildpacks/occam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

github.com/paketo-buildpacks/occam

GoDoc

occam is a Go library that provides an integration test framework that can be used to test Paketo Buildpacks

Usage

go get github.com/paketo-buildpacks/occam

Examples

Package a buildpack

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())

Important update: Libpak v2.0.0+

As of version 2.0.0 of libpak, the implementation of create-package has changed and instead the binaries from libpak tools are being used. For backward compatibility and easier transition to libpak 2.0.0, a new packager was introduced:

The new packager is named NewLibpakTools and you can use it in the same way as NewLibpak by calling it like this:

buildpackStore := occam.NewBuildpackStore().
    WithPackager(packagers.NewLibpakTools())

In both cases the libpak need to be installed and available in your environemt. For libpak prior to 2.0.0 you can find the installation process on below url:

For versions 2.0.0 and above you can find the installation process on below url:

Test a buildpack

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))

Test a container image with container structure tests

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, ...)

Use venom to extent your integration test

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, ...)

License

This library is released under version 2.0 of the Apache License.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 25