occam

package module
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 25 Imported by: 6

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheVolumeNames

func CacheVolumeNames(name string) []string

func RandomName

func RandomName() (string, error)

func Source added in v0.0.11

func Source(path string) (string, error)

Types

type Builder added in v0.13.0

type Builder struct {
	BuilderName string      `json:"builder_name"`
	Trusted     bool        `json:"trusted"`
	Default     bool        `json:"default"`
	LocalInfo   BuilderInfo `json:"local_info"`
	RemoteInfo  BuilderInfo `json:"remote_info"`
}

type BuilderInfo added in v0.13.0

type BuilderInfo struct {
	Description    string                      `json:"description"`
	CreatedBy      BuilderInfoCreatedBy        `json:"created_by"`
	Stack          BuilderInfoStack            `json:"stack"`
	Lifecycle      BuilderInfoLifecycle        `json:"lifecycle"`
	RunImages      []BuilderInfoRunImage       `json:"run_images"`
	Buildpacks     []BuilderInfoBuildpack      `json:"buildpacks"`
	DetectionOrder []BuilderInfoDetectionOrder `json:"detection_order"`
}

type BuilderInfoBuildpack added in v0.13.0

type BuilderInfoBuildpack struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Version  string `json:"version"`
	Homepage string `json:"homepage"`
}

type BuilderInfoCreatedBy added in v0.13.0

type BuilderInfoCreatedBy struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type BuilderInfoDetectionOrder added in v0.13.0

type BuilderInfoDetectionOrder struct {
	Buildpacks []BuilderInfoDetectionOrderBuildpack `json:"buildpacks"`
}

type BuilderInfoDetectionOrderBuildpack added in v0.13.0

type BuilderInfoDetectionOrderBuildpack struct {
	ID         string                               `json:"id"`
	Version    string                               `json:"version"`
	Optional   bool                                 `json:"optional,omitempty"`
	Buildpacks []BuilderInfoDetectionOrderBuildpack `json:"buildpacks"`
}

type BuilderInfoLifecycle added in v0.13.0

type BuilderInfoLifecycle struct {
	Version       string                   `json:"version"`
	BuildpackAPIs BuilderInfoLifecycleAPIs `json:"buildpack_apis"`
	PlatformAPIs  BuilderInfoLifecycleAPIs `json:"platform_apis"`
}

type BuilderInfoLifecycleAPIs added in v0.13.0

type BuilderInfoLifecycleAPIs struct {
	Deprecated []string `json:"deprecated"`
	Supported  []string `json:"supported"`
}

type BuilderInfoRunImage added in v0.13.0

type BuilderInfoRunImage struct {
	Name string `json:"name"`
}

type BuilderInfoStack added in v0.13.0

type BuilderInfoStack struct {
	ID string `json:"id"`
}

type BuildpackStore added in v0.0.12

type BuildpackStore struct {
	Get BuildpackStoreGet
}

func NewBuildpackStore added in v0.0.12

func NewBuildpackStore() BuildpackStore

func (BuildpackStore) WithCacheManager added in v0.0.12

func (bs BuildpackStore) WithCacheManager(manager CacheManager) BuildpackStore

func (BuildpackStore) WithLocalFetcher added in v0.0.12

func (bs BuildpackStore) WithLocalFetcher(fetcher LocalFetcher) BuildpackStore

func (BuildpackStore) WithPackager added in v0.2.0

func (bs BuildpackStore) WithPackager(packager freezer.Packager) BuildpackStore

func (BuildpackStore) WithRemoteFetcher added in v0.0.12

func (bs BuildpackStore) WithRemoteFetcher(fetcher RemoteFetcher) BuildpackStore

type BuildpackStoreGet added in v0.0.12

type BuildpackStoreGet struct {
	// contains filtered or unexported fields
}

func (BuildpackStoreGet) Execute added in v0.0.12

func (g BuildpackStoreGet) Execute(url string) (string, error)

func (BuildpackStoreGet) WithOfflineDependencies added in v0.0.12

func (g BuildpackStoreGet) WithOfflineDependencies() BuildpackStoreGet

func (BuildpackStoreGet) WithVersion added in v0.0.12

func (g BuildpackStoreGet) WithVersion(version string) BuildpackStoreGet

type CacheManager added in v0.0.12

type CacheManager interface {
	Get(key string) (freezer.CacheEntry, bool, error)
	Set(key string, cachedEntry freezer.CacheEntry) error
	Dir() string
	Open() error
	Close() error
}

type Container

type Container struct {
	ID          string
	Ports       map[string]string
	Env         map[string]string
	IPAddresses map[string]string
}

func NewContainerFromInspectOutput

func NewContainerFromInspectOutput(output []byte) (Container, error)

func (Container) Host added in v0.4.0

func (c Container) Host() string

func (Container) HostPort

func (c Container) HostPort(value string) string

func (Container) IPAddressForNetwork added in v0.8.0

func (c Container) IPAddressForNetwork(networkName string) (string, error)

type ContainerStructureTest added in v0.9.0

type ContainerStructureTest struct {
	// contains filtered or unexported fields
}

func NewContainerStructureTest added in v0.9.0

func NewContainerStructureTest() ContainerStructureTest

func (ContainerStructureTest) Execute added in v0.9.0

func (r ContainerStructureTest) Execute(imageID string, config string) (string, error)

func (ContainerStructureTest) WithExecutable added in v0.9.0

func (c ContainerStructureTest) WithExecutable(executable Executable) ContainerStructureTest

func (ContainerStructureTest) WithNoColor added in v0.9.0

func (ContainerStructureTest) WithPull added in v0.9.0

func (ContainerStructureTest) WithVerbose added in v0.9.0

type Docker

type Docker struct {
	Image struct {
		ExportToOCI DockerImageOCI
		Inspect     DockerImageInspect
		Remove      DockerImageRemove
		Tag         DockerImageTag
	}

	Container struct {
		Copy    DockerContainerCopy
		Exec    DockerContainerExec
		Inspect DockerContainerInspect
		Logs    DockerContainerLogs
		Remove  DockerContainerRemove
		Restart DockerContainerRestart
		Run     DockerContainerRun
		Stop    DockerContainerStop
	}

	Volume struct {
		Remove DockerVolumeRemove
	}

	Pull DockerPull
}

func NewDocker

func NewDocker() Docker

func (Docker) WithExecutable

func (d Docker) WithExecutable(executable Executable) Docker

type DockerContainerCopy added in v0.12.0

type DockerContainerCopy struct {
	// contains filtered or unexported fields
}

func (DockerContainerCopy) Execute added in v0.12.0

func (docker DockerContainerCopy) Execute(source, dest string) error

type DockerContainerExec added in v0.12.0

type DockerContainerExec struct {
	// contains filtered or unexported fields
}

func (DockerContainerExec) Execute added in v0.12.0

func (e DockerContainerExec) Execute(container string, arguments ...string) error

func (DockerContainerExec) ExecuteBash added in v0.12.0

func (e DockerContainerExec) ExecuteBash(container, script string) error

func (DockerContainerExec) WithInteractive added in v0.16.0

func (e DockerContainerExec) WithInteractive() DockerContainerExec

func (DockerContainerExec) WithStdin added in v0.16.0

func (e DockerContainerExec) WithStdin(stdin io.Reader) DockerContainerExec

func (DockerContainerExec) WithUser added in v0.16.0

type DockerContainerInspect

type DockerContainerInspect struct {
	// contains filtered or unexported fields
}

func (DockerContainerInspect) Execute

func (i DockerContainerInspect) Execute(containerID string) (Container, error)

type DockerContainerLogs

type DockerContainerLogs struct {
	// contains filtered or unexported fields
}

func (DockerContainerLogs) Execute

func (l DockerContainerLogs) Execute(containerID string) (fmt.Stringer, error)

type DockerContainerRemove

type DockerContainerRemove struct {
	// contains filtered or unexported fields
}

func (DockerContainerRemove) Execute

func (r DockerContainerRemove) Execute(containerID string) error

type DockerContainerRestart added in v0.11.0

type DockerContainerRestart struct {
	// contains filtered or unexported fields
}

func (DockerContainerRestart) Execute added in v0.11.0

func (r DockerContainerRestart) Execute(containerID string) error

type DockerContainerRun

type DockerContainerRun struct {
	// contains filtered or unexported fields
}

func (DockerContainerRun) Execute

func (r DockerContainerRun) Execute(imageID string) (Container, error)

func (DockerContainerRun) WithCommand

func (r DockerContainerRun) WithCommand(command string) DockerContainerRun

func (DockerContainerRun) WithCommandArgs added in v0.9.0

func (r DockerContainerRun) WithCommandArgs(commandArgs []string) DockerContainerRun

func (DockerContainerRun) WithDirect added in v0.9.0

func (r DockerContainerRun) WithDirect() DockerContainerRun

func (DockerContainerRun) WithEntrypoint added in v0.0.18

func (r DockerContainerRun) WithEntrypoint(entrypoint string) DockerContainerRun

func (DockerContainerRun) WithEnv

func (DockerContainerRun) WithMemory

func (r DockerContainerRun) WithMemory(memoryLimit string) DockerContainerRun

func (DockerContainerRun) WithMounts added in v0.10.0

func (r DockerContainerRun) WithMounts(mounts ...string) DockerContainerRun

func (DockerContainerRun) WithNetwork added in v0.7.0

func (r DockerContainerRun) WithNetwork(network string) DockerContainerRun

func (DockerContainerRun) WithPublish added in v0.0.21

func (r DockerContainerRun) WithPublish(value string) DockerContainerRun

func (DockerContainerRun) WithPublishAll added in v0.0.21

func (r DockerContainerRun) WithPublishAll() DockerContainerRun

func (DockerContainerRun) WithReadOnly added in v0.10.0

func (r DockerContainerRun) WithReadOnly() DockerContainerRun

func (DockerContainerRun) WithTTY

func (DockerContainerRun) WithVolume deprecated added in v0.1.2

func (r DockerContainerRun) WithVolume(volume string) DockerContainerRun

Deprecated: Use WithVolumes(...volumes) instead.

func (DockerContainerRun) WithVolumes added in v0.3.0

func (r DockerContainerRun) WithVolumes(volumes ...string) DockerContainerRun

type DockerContainerStop added in v0.0.19

type DockerContainerStop struct {
	// contains filtered or unexported fields
}

func (DockerContainerStop) Execute added in v0.0.19

func (s DockerContainerStop) Execute(containerID string) error

type DockerDaemonClient added in v0.18.0

type DockerDaemonClient interface {
	daemon.Client
}

type DockerImageInspect

type DockerImageInspect struct {
	// contains filtered or unexported fields
}

func (DockerImageInspect) Execute

func (i DockerImageInspect) Execute(ref string) (Image, error)

type DockerImageInspectClient

type DockerImageInspectClient interface {
	Execute(ref string) (Image, error)
}

type DockerImageOCI added in v0.18.0

type DockerImageOCI struct {
	// contains filtered or unexported fields
}

func (DockerImageOCI) Execute added in v0.18.0

func (r DockerImageOCI) Execute(ref string) (v1.Image, error)

func (DockerImageOCI) WithClient added in v0.18.0

func (r DockerImageOCI) WithClient(client DockerDaemonClient) DockerImageOCI

func (DockerImageOCI) WithNameOptions added in v0.18.0

func (r DockerImageOCI) WithNameOptions(opts ...name.Option) DockerImageOCI

type DockerImageRemove

type DockerImageRemove struct {
	// contains filtered or unexported fields
}

func (DockerImageRemove) Execute

func (r DockerImageRemove) Execute(ref string) error

func (DockerImageRemove) WithForce added in v0.15.0

func (r DockerImageRemove) WithForce() DockerImageRemove

type DockerImageTag added in v0.15.0

type DockerImageTag struct {
	// contains filtered or unexported fields
}

func (DockerImageTag) Execute added in v0.15.0

func (r DockerImageTag) Execute(ref, target string) error

type DockerPull added in v0.6.0

type DockerPull struct {
	// contains filtered or unexported fields
}

func (DockerPull) Execute added in v0.6.0

func (p DockerPull) Execute(image string) error

type DockerVolumeRemove

type DockerVolumeRemove struct {
	// contains filtered or unexported fields
}

func (DockerVolumeRemove) Execute

func (r DockerVolumeRemove) Execute(volumes []string) error

type Executable

type Executable interface {
	Execute(pexec.Execution) error
}

type Image

type Image struct {
	ID         string
	Buildpacks []ImageBuildpackMetadata
	Labels     map[string]string
}

func NewImageFromInspectOutput

func NewImageFromInspectOutput(output []byte) (Image, error)

func (Image) BuildpackForKey added in v0.13.1

func (i Image) BuildpackForKey(key string) (ImageBuildpackMetadata, error)

type ImageBuildpackMetadata

type ImageBuildpackMetadata struct {
	Key    string
	Layers map[string]ImageBuildpackMetadataLayer
}

type ImageBuildpackMetadataLayer

type ImageBuildpackMetadataLayer struct {
	SHA      string
	Build    bool
	Launch   bool
	Cache    bool
	Metadata map[string]interface{}
}

type LocalFetcher added in v0.0.12

type LocalFetcher interface {
	WithPackager(packager freezer.Packager) freezer.LocalFetcher
	Get(freezer.LocalBuildpack) (string, error)
}

type Pack

type Pack struct {
	Build   PackBuild
	Builder PackBuilder
}

func NewPack

func NewPack() Pack

func (Pack) WithDockerImageInspectClient

func (p Pack) WithDockerImageInspectClient(client DockerImageInspectClient) Pack

func (Pack) WithExecutable

func (p Pack) WithExecutable(executable Executable) Pack

func (Pack) WithNoColor

func (p Pack) WithNoColor() Pack

func (Pack) WithVerbose

func (p Pack) WithVerbose() Pack

type PackBuild

type PackBuild struct {
	// contains filtered or unexported fields
}

func (PackBuild) Execute

func (pb PackBuild) Execute(name, path string) (Image, fmt.Stringer, error)

func (PackBuild) WithAdditionalBuildArgs added in v0.18.0

func (pb PackBuild) WithAdditionalBuildArgs(args ...string) PackBuild

func (PackBuild) WithBuilder

func (pb PackBuild) WithBuilder(name string) PackBuild

func (PackBuild) WithBuildpacks

func (pb PackBuild) WithBuildpacks(buildpacks ...string) PackBuild

func (PackBuild) WithClearCache

func (pb PackBuild) WithClearCache() PackBuild

func (PackBuild) WithEnv

func (pb PackBuild) WithEnv(env map[string]string) PackBuild

func (PackBuild) WithExtensions added in v0.17.0

func (pb PackBuild) WithExtensions(extensions ...string) PackBuild

func (PackBuild) WithGID added in v0.4.0

func (pb PackBuild) WithGID(gid string) PackBuild

func (PackBuild) WithNetwork

func (pb PackBuild) WithNetwork(name string) PackBuild

func (PackBuild) WithNoPull deprecated

func (pb PackBuild) WithNoPull() PackBuild

Deprecated: Use WithPullPolicy("never") instead.

func (PackBuild) WithPullPolicy added in v0.0.19

func (pb PackBuild) WithPullPolicy(pullPolicy string) PackBuild

func (PackBuild) WithRunImage added in v0.18.0

func (pb PackBuild) WithRunImage(runImage string) PackBuild

func (PackBuild) WithSBOMOutputDir added in v0.5.0

func (pb PackBuild) WithSBOMOutputDir(output string) PackBuild

func (PackBuild) WithTrustBuilder added in v0.0.18

func (pb PackBuild) WithTrustBuilder() PackBuild

func (PackBuild) WithVolumes added in v0.3.0

func (pb PackBuild) WithVolumes(volumes ...string) PackBuild

type PackBuilder added in v0.13.0

type PackBuilder struct {
	Inspect PackBuilderInspect
}

type PackBuilderInspect added in v0.13.0

type PackBuilderInspect struct {
	// contains filtered or unexported fields
}

func (PackBuilderInspect) Execute added in v0.13.0

func (pbi PackBuilderInspect) Execute(names ...string) (Builder, error)

type RemoteFetcher added in v0.0.12

type RemoteFetcher interface {
	WithPackager(packager freezer.Packager) freezer.RemoteFetcher
	Get(freezer.RemoteBuildpack) (string, error)
}

type TestContainers added in v0.9.0

type TestContainers struct {
	// contains filtered or unexported fields
}

func NewTestContainers added in v0.9.0

func NewTestContainers() TestContainers

func (TestContainers) Execute added in v0.9.0

func (r TestContainers) Execute(imageID string) (testcontainers.Container, error)

func (TestContainers) WithEnv added in v0.9.0

func (r TestContainers) WithEnv(env map[string]string) TestContainers

func (TestContainers) WithExposedPorts added in v0.9.0

func (r TestContainers) WithExposedPorts(values ...string) TestContainers

func (TestContainers) WithMounts added in v0.9.0

func (r TestContainers) WithMounts(containerMounts ...testcontainers.ContainerMount) TestContainers

func (TestContainers) WithNoStart added in v0.9.0

func (r TestContainers) WithNoStart() TestContainers

func (TestContainers) WithTimeout added in v0.9.0

func (r TestContainers) WithTimeout(t int) TestContainers

func (TestContainers) WithWaitingFor added in v0.9.0

func (r TestContainers) WithWaitingFor(waitStrategy wait.Strategy) TestContainers

type Venom added in v0.9.0

type Venom struct {
	// contains filtered or unexported fields
}

func NewVenom added in v0.9.0

func NewVenom() Venom

func (Venom) Execute added in v0.9.0

func (v Venom) Execute(venomPath string) (string, error)

func (Venom) WithExecutable added in v0.9.0

func (v Venom) WithExecutable(executable Executable) Venom

func (Venom) WithNamedPort added in v0.9.0

func (v Venom) WithNamedPort(name string, port string) Venom

func (Venom) WithPort added in v0.9.0

func (v Venom) WithPort(port string) Venom

func (Venom) WithVar added in v0.9.0

func (v Venom) WithVar(name string, value string) Venom

func (Venom) WithVerbose added in v0.9.0

func (v Venom) WithVerbose() Venom

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL