Struct testcontainers_modules::postgres::Postgres

source ·
pub struct Postgres { /* private fields */ }
Available on crate feature postgres only.
Expand description

Module to work with Postgres inside of tests.

Starts an instance of Postgres. This module is based on the official Postgres docker image.

Default db name, user and password is postgres.

§Example

use testcontainers_modules::{postgres, testcontainers::runners::SyncRunner};

let postgres_instance = postgres::Postgres::default().start().unwrap();

let connection_string = format!(
    "postgres://postgres:postgres@{}:{}/postgres",
    postgres_instance.get_host().unwrap(),
    postgres_instance.get_host_port_ipv4(5432).unwrap()
);

Implementations§

source§

impl Postgres

source

pub fn with_host_auth(self) -> Self

Enables the Postgres instance to be used without authentication on host. For more information see the description of POSTGRES_HOST_AUTH_METHOD in official docker image

source

pub fn with_db_name(self, db_name: &str) -> Self

Sets the db name for the Postgres instance.

source

pub fn with_user(self, user: &str) -> Self

Sets the user for the Postgres instance.

source

pub fn with_password(self, password: &str) -> Self

Sets the password for the Postgres instance.

Trait Implementations§

source§

impl Debug for Postgres

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Postgres

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Image for Postgres

source§

fn name(&self) -> &str

The name of the docker image to pull from the Docker Hub registry.
source§

fn tag(&self) -> &str

Implementations are encouraged to include a tag that will not change (i.e. NOT latest) in order to prevent test code from randomly breaking because the underlying docker suddenly changed.
source§

fn ready_conditions(&self) -> Vec<WaitFor>

Returns a list of conditions that need to be met before a started container is considered ready. Read more
source§

fn env_vars( &self, ) -> impl IntoIterator<Item = (impl Into<Cow<'_, str>>, impl Into<Cow<'_, str>>)>

Returns the environment variables that needs to be set when a container is created.
source§

fn mounts(&self) -> impl IntoIterator<Item = &Mount>

Returns the mounts that needs to be created when a container is created.
source§

fn entrypoint(&self) -> Option<&str>

Returns the entrypoint this image needs to be created with.
source§

fn cmd(&self) -> impl IntoIterator<Item = impl Into<Cow<'_, str>>>

Returns the CMD this image needs to be created with.
source§

fn expose_ports(&self) -> &[ContainerPort]

Returns the ports that needs to be exposed when a container is created. Read more
source§

fn exec_after_start( &self, cs: ContainerState, ) -> Result<Vec<ExecCommand>, TestcontainersError>

Returns the commands that needs to be executed after a container is started i.e. commands to be run in a running container. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T, I> AsyncRunner<I> for T
where T: Into<ContainerRequest<I>> + Send, I: Image,

source§

fn start<'async_trait>( self, ) -> Pin<Box<dyn Future<Output = Result<ContainerAsync<I>, TestcontainersError>> + Send + 'async_trait>>
where T: 'async_trait,

Starts the container and returns an instance of ContainerAsync.
source§

fn pull_image<'async_trait>( self, ) -> Pin<Box<dyn Future<Output = Result<ContainerRequest<I>, TestcontainersError>> + Send + 'async_trait>>
where T: 'async_trait,

Pulls the image from the registry. Useful if you want to pull the image before starting the container.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<RI, I> ImageExt<I> for RI
where RI: Into<ContainerRequest<I>>, I: Image,

source§

fn with_cmd( self, cmd: impl IntoIterator<Item = impl Into<String>>, ) -> ContainerRequest<I>

Returns a new ContainerRequest with the specified (overridden) CMD (Image::cmd). Read more
source§

fn with_name(self, name: impl Into<String>) -> ContainerRequest<I>

Overrides the fully qualified image name (consists of {domain}/{owner}/{image}). Can be used to specify a custom registry or owner.
source§

fn with_tag(self, tag: impl Into<String>) -> ContainerRequest<I>

Overrides the image tag. Read more
source§

fn with_container_name(self, name: impl Into<String>) -> ContainerRequest<I>

Sets the container name.
source§

fn with_network(self, network: impl Into<String>) -> ContainerRequest<I>

Sets the network the container will be connected to.
source§

fn with_env_var( self, name: impl Into<String>, value: impl Into<String>, ) -> ContainerRequest<I>

Adds an environment variable to the container.
source§

fn with_host( self, key: impl Into<String>, value: impl Into<Host>, ) -> ContainerRequest<I>

Adds a host to the container.
source§

fn with_mount(self, mount: impl Into<Mount>) -> ContainerRequest<I>

Adds a mount to the container.
source§

fn with_mapped_port( self, host_port: u16, container_port: ContainerPort, ) -> ContainerRequest<I>

Adds a port mapping to the container, mapping the host port to the container’s internal port. Read more
source§

fn with_privileged(self, privileged: bool) -> ContainerRequest<I>

Sets the container to run in privileged mode.
source§

fn with_cgroupns_mode(self, cgroupns_mode: CgroupnsMode) -> ContainerRequest<I>

cgroup namespace mode for the container. Possible values are: Read more
source§

fn with_userns_mode(self, userns_mode: &str) -> ContainerRequest<I>

Sets the usernamespace mode for the container when usernamespace remapping option is enabled.
source§

fn with_shm_size(self, bytes: u64) -> ContainerRequest<I>

Sets the shared memory size in bytes
source§

fn with_startup_timeout(self, timeout: Duration) -> ContainerRequest<I>

Sets the startup timeout for the container. The default is 60 seconds.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> IntoResult<T> for T

§

type Err = Infallible

source§

fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>

source§

impl<T, I> SyncRunner<I> for T
where T: Into<ContainerRequest<I>> + Send, I: Image,

source§

fn start(self) -> Result<Container<I>, TestcontainersError>

Starts the container and returns an instance of Container.
source§

fn pull_image(self) -> Result<ContainerRequest<I>, TestcontainersError>

Pulls the image from the registry. Useful if you want to pull the image before starting the container.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more