testcontainers-demo

command module
v0.0.0-...-829a616 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2025 License: MIT Imports: 17 Imported by: 0

README

Emulating real dependencies in Integration Tests using Testcontainers

We built a dead simple URL shortener API in Go with 2 endpoints:

  • /create?url= - shortens the given URL.
  • /get?key= - returns the original URL for a given key.

It has 2 dependencies:

  • MongoDB as the database.
  • Redis for caching.

Run unit tests

Uses mocks created with mockery as dependencies.

See unit_test.go file for more implementation.

mockery --all --with-expecter
go test -v ./...

Run integration tests using Testcontainers

See integration_test.go file for more implementation.

The first run may take a while to download the images. But the subsequent runs are almost instant.

go test -tags=integration -v ./...

Run integration tests with real dependencies

See realdeps_test.go file for more implementation. Make sure to start the services before running the tests.

docker-compose up -d
go test -tags=realdeps -v ./...

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL