Hi all, I was making a proof of concept to use dagger as a service provider for integration tests in python with pytest library.
So the workflow I tried is to define a fixture that creates a postgres container exposing the port. Then within a test I can successfully get the container's endpoint, but failing to connect to it as I'm not running the tests from a dagger pipeline and can't bind the service.
What do you suggest for connecting to the postgres container ?
Sample code here:
@pytest.fixture(scope="session")
async def postgres_service():
async with dagger.Connection() as client:
postgres = (
dagger_client.container()
.from_("postgres")
.with_env_variable("POSTGRES_USER", "postgres")
.with_env_variable("POSTGRES_PASSWORD", "postgres")
.with_env_variable("POSTGRES_DB", "postgres")
.with_exposed_port(5432)
)
return await postgres.endpoint()
@pytest.mark.asyncio
async def test_query(postgres_service):
service_endpoint = await postgres_service
host = service_endpoint.split(":")[0]
## host is k1hh5md0ptupo, so the fixture works fine
db_url = f"dbname=postgres user=postgres password=postgres host={host} port=5432"
conn = connect_db(db_url)
cur = conn.cursor()
cur.execute("SELECT 'Hello, World!'")
result = cur.fetchall()
cur.close()
conn.close()
assert result == [("Hello, World!",)]