testcontainers / testcontainers-hs

Docker containers for your integration tests! http://hackage.haskell.org/package/testcontainers
MIT License
56 stars 12 forks source link

Add possibility to get Network value without creating network? #40

Closed jhrcek closed 1 year ago

jhrcek commented 1 year ago

Hello @alexbiehl today I tried updating our tests to use testcontainers-0.5.0.0 and found out the new API has no easy way to specify --network without actually creating new network.

Till now we were using setNetwork added by my colleague in https://github.com/testcontainers/testcontainers-hs/pull/20

In 0.5.0.0 I see withNetwork function, but it requires value of type Network. Looking at source code it seems that the only way to create value of this (opaque) type is through createNetwork which calls docker create.

But what if (as we're doing in CI) you want to connect to a network that was created for us outside of test logic? I'd still be like to run docker container using this library, connecting to such network. But in the current API there doesn't seem to be way to do that (unless I'm missing something).

What would you say to adding something like a following function to allow for this usecase?

fromExistingNetwork :: NetworkId -> Network
fromExistingNetwork = Network

Or if you want to be extra careful (verifying that network with such a name exists, you could call docker network ls or docker network inspect..

alexbiehl commented 1 year ago

Thanks for raising the issue @jhrcek. The testcontainers-hs got revamped quite a bit with version 0.5.0.0. In particular, the philosophy of testcontainers is to isolate all the things and have automatic resource cleanup after. The general recommendation is to follow the isolation. But I am not opposed to adding the function that you proposed.

Let me open a PR and we can discuss over there.

jhrcek commented 1 year ago

Closing as resolved by https://github.com/testcontainers/testcontainers-hs/pull/41. Thanks for implementing my suggestion!