testcontainers-python
testcontainers-go
Our great sponsors
testcontainers-python | testcontainers-go | |
---|---|---|
8 | 18 | |
1,304 | 3,115 | |
15.8% | 10.1% | |
9.0 | 9.7 | |
3 days ago | 2 days ago | |
Python | Go | |
Apache License 2.0 | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
testcontainers-python
-
Mock unit test an API that uses postgres or integration test API with a "test" database?
For later stuff, I tend to go all the way, have a separate database that gets seeded, all tests are performed against it, then it gets shut down. Testcontainers work well with this.
- Is this really what I have to do to test?
-
Ask HN: I have 10 yrs of Exp. Failed 4 takehome projects. What am I doing wrong?
> ...
I think this is where we're talking past each other, so let me explain more of how I see the problem -- the solution I have in mind is serializing the URL and using ONE call to INCR (https://redis.io/commands/incr/) on the ingest side.
There is a lot you can do with the data storage pattern to make other operations more efficient, but on the stats side, the most basic way you can do it is to scan
I will concede that given that we know the data should fit in memory (otherwise you just crash) your approach gives you O(N) retrieval time and it's definitely superior to not have to do that on the python side (and python just streaming the response through). I am comfortable optimizing in-API computation, so I don't think it's a problem.
Here's what I mean -- you can actually solve the ordering problem in O(N) + O(M) time by keeping track of the max you've seen and building a sparse array and running through every single index from max to zero. It's overkill, but it's generally referred to as a counting sort:
https://ebrary.net/81651/geography/sorting_algorithms
This is overkill, clearly, and I will concede that ZSET is lighter and easier to get right than this.
> You linked? Where? I'd like to know about any library that will do this. Tell me of any library that does integration tests that spins up infrastructure for you. The only one closest I can think of that you can run locally is anything that would use docker-compose or some other IAC language that controls containers. I honestly don't think any popular ones exist.
https://testcontainers-python.readthedocs.io/en/latest/
I am very sure that I linked that, but in the case I didn't, here it is again -- hope you find it useful.
> No way I'm going to assume the user has redis installed on his local machine. Many devs don't. It's all remote development for them or everything lives in containers.
-
What we learned after I deleted the main production database by mistake
Have a script for spinning up an identical database model in a docker container with your DB of choice. Even nicer than the manual route is depending on your language there's normally some sort of "testcontainers" type library (e.g in Java world https://www.testcontainers.org/ or in PYthon world https://github.com/testcontainers/testcontainers-python) that allows you to run a test that automatically spins up a container then you can use the network connection and run tests against it. E.g If I was testing a postgres integration my test would look like
-
Python/testcontainers
I have been using TestContainers for my Java projects for a while now with great success and my plan is to use it for some Python projects. I notice that the https://github.com/testcontainers/testcontainers-python project doesn't seem to be under active development. Are there any alternatives out there the community is using/developing?
-
orchestrating contaiers for testing?
- https://github.com/praekeltfoundation/seaworthy but you have to recreate a manifest with code. Not ideal for mildly complex stuff. 3+years was last commit :(( - https://github.com/testcontainers/testcontainers-python which is weirdly specific to certain container images. Again, not working off a manifest (I think), 1 months since last commit. :( - https://github.com/vapor-ware/kubetest which uses kubernetes(k8s) manifests and integrates with pyTest. Last commit 10 month ago.
-
The absolute worst but common anti-pattern that no one talks about
Buddy, let me juice it up even more: https://github.com/testcontainers/testcontainers-python
-
Hazelcast, from Embedded to Client-Server
Those are great options if you're developing in Java, but all is not lost if you aren't. Containerization can help us a lot! For example, the TestContainers project is available in all stack that Hazelcast support: Python developers can easily leverage the Python project to set up a local Hazelcast cluster quickly, Go developers the Go project, C# developers the .Net project, etc.
testcontainers-go
-
Using test helpers in Go
Let's first look at the original version of the test, in this case, an end-to-end, using testcontainers.
-
Run and test DynamoDB applications locally using Docker and Testcontainers
It supports multiple languages (including Go!) and databases (also messaging infrastructure etc.) - All you need is Docker. Testcontainers for Go makes it simple to programmatically create and clean up container-based dependencies for automated integration/smoke tests. You can define test dependencies as code, run tests and delete the containers once done.
-
๐ Effortless Integration Tests with Testcontainers in Golang ๐งช
Testcontainers Go Documentation
-
go-ecommerce-microservices: A practical e-commerce microservices, built with cqrs, event sourcing, vertical slice architecture, event-driven architecture.
Some of the features: - โ Using Vertical Slice Architecture as a high level architecture - โ Using Event Driven Architecture on top of RabbitMQ Message Broker with a custom [Event Bus](pkg/messaging/bus/) - โ Using Event Sourcing in Audit Based services like [Orders Service](services/orders/) - โ Using CQRS Pattern and Mediator Patternon top of Go-MediatR library - โ Using Dependency Injection and Inversion of Controlon top of uber-go/fx library - โ Using RESTFul api with Echo framework and using swagger with swaggo/swag library - โ Using Postgres and EventStoreDB to write databases with fully supports transactions(ACID) - โ Using MongoDB and Elastic Search for read databases (NOSQL) - โ Using OpenTelemetry for collection Distributed Tracing with using Jaeger and Zipkin - โ Using OpenTelemetry for collection Metrics with using Prometheus and Grafana - โ Using Unit Test for testing small units with mocking dependent classes and using Mockery for mocking dependencies - โ Using End2End Test and Integration Test for testing features with all of their real dependeinces using docker containers (cleanup tests) and testcontainers-go library
- How to start a Go project in 2023
-
Questions about Interfacing for Unit-Tests
For example, you could take a look at this open-source project that helps you spawn docker containers as part of your test setup enabling you to execute queries to a local database.
-
How to Work with SQL Databases in Go
Using something like TestContainers to spin up a DB for testing has been my best experience. Any mocks leave too much room for error imo
-
Different SQL drivers for test and production
I highly recommend testcontainers for this.
-
Go API Project Set-Up
The next block in .gitlab-ci.yml is the services block. Since our tests use testcontainers package and we're pushing a docker container onto Dockerhub, we will need to specify a services block next. Services will enable our pipeline to leverage Docker-in-Docker DinD.
- Do you test your API, repositories, & services together (e.g., e2e) or separately?
What are some alternatives?
LocalStack - ๐ป A fully functional local AWS cloud stack. Develop and test your cloud & Serverless apps offline
dockertest - Write better integration tests! Dockertest helps you boot up ephermal docker images for your Go tests with minimal work.
testcontainers-dotnet - A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
otj-pg-embedded - Java embedded PostgreSQL component for testing
kubetest - Kubernetes integration testing in Python via pytest
venom - ๐ Manage and run your integration tests with efficiency - Venom run executors (script, HTTP Request, web, imap, etc... ) and assertions
seaworthy - Test harness for Docker container images ๐ ๐ข
charts - Hazelcast Official Helm Chart Repository
localstripe - A fake but stateful Stripe server that you can run locally, for testing purposes.
helium - Selenium-python but lighter: Helium is the best Python library for web automation. [Moved to: https://github.com/mherrmann/selenium-python-helium]
integresql - IntegreSQL manages isolated PostgreSQL databases for your integration tests.