diff options
| author | mo khan <mo@mokhan.ca> | 2025-05-11 21:22:43 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-05-11 21:22:43 -0600 |
| commit | 05fae21a33b74e7768a94eb84294f6198c3cec56 (patch) | |
| tree | fce6d4813f10704d3d17ba69e235e097da1f0574 /vendor/github.com/testcontainers/testcontainers-go/mounts.go | |
| parent | b1b29603622451f677f61be9300987ee3e79a2ff (diff) | |
chore: update go modules
Diffstat (limited to 'vendor/github.com/testcontainers/testcontainers-go/mounts.go')
| -rw-r--r-- | vendor/github.com/testcontainers/testcontainers-go/mounts.go | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/vendor/github.com/testcontainers/testcontainers-go/mounts.go b/vendor/github.com/testcontainers/testcontainers-go/mounts.go index a68e468..2e1d2c7 100644 --- a/vendor/github.com/testcontainers/testcontainers-go/mounts.go +++ b/vendor/github.com/testcontainers/testcontainers-go/mounts.go @@ -1,12 +1,16 @@ package testcontainers -import "errors" +import ( + "errors" + "path/filepath" +) const ( MountTypeBind MountType = iota // Deprecated: Use MountTypeVolume instead MountTypeVolume MountTypeTmpfs MountTypePipe + MountTypeImage ) var ( @@ -18,6 +22,7 @@ var ( _ ContainerMountSource = (*GenericBindMountSource)(nil) // Deprecated: use Files or HostConfigModifier in the ContainerRequest, or copy files container APIs to make containers portable across Docker environments _ ContainerMountSource = (*GenericVolumeMountSource)(nil) _ ContainerMountSource = (*GenericTmpfsMountSource)(nil) + _ ContainerMountSource = (*GenericImageMountSource)(nil) ) type ( @@ -110,6 +115,15 @@ func VolumeMount(volumeName string, mountTarget ContainerMountTarget) ContainerM } } +// ImageMount returns a new ContainerMount with a GenericImageMountSource as source +// This is a convenience method to cover typical use cases. +func ImageMount(imageName string, subpath string, mountTarget ContainerMountTarget) ContainerMount { + return ContainerMount{ + Source: NewGenericImageMountSource(imageName, subpath), + Target: mountTarget, + } +} + // Mounts returns a ContainerMounts to support a more fluent API func Mounts(mounts ...ContainerMount) ContainerMounts { return mounts @@ -124,3 +138,38 @@ type ContainerMount struct { // ReadOnly determines if the mount should be read-only ReadOnly bool } + +// GenericImageMountSource implements ContainerMountSource and represents an image mount +type GenericImageMountSource struct { + // imageName refers to the name of the image to be mounted + // the same image might be mounted to multiple locations within a single container + imageName string + // subpath is the path within the image to be mounted + subpath string +} + +// NewGenericImageMountSource creates a new GenericImageMountSource +func NewGenericImageMountSource(imageName string, subpath string) GenericImageMountSource { + return GenericImageMountSource{ + imageName: imageName, + subpath: subpath, + } +} + +// Source returns the name of the image to be mounted +func (s GenericImageMountSource) Source() string { + return s.imageName +} + +// Type returns the type of the mount +func (GenericImageMountSource) Type() MountType { + return MountTypeImage +} + +// Validate validates the source of the mount +func (s GenericImageMountSource) Validate() error { + if !filepath.IsLocal(s.subpath) { + return errors.New("image mount source must be a local path") + } + return nil +} |
