Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
TestContainers-Go
Search
Erdem Toraman
January 23, 2020
Programming
0
94
TestContainers-Go
Erdem Toraman
January 23, 2020
Tweet
Share
Other Decks in Programming
See All in Programming
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
200
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
160
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
0
910
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
6k
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
180
Fluid Templating in TYPO3 14
s2b
0
130
「ブロックテーマでは再現できない」は本当か?
inc2734
0
600
CSC307 Lecture 08
javiergs
PRO
0
670
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
510
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
400
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
250
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
Featured
See All Featured
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
66
36k
Odyssey Design
rkendrick25
PRO
1
490
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
0
270
Mobile First: as difficult as doing things right
swwweet
225
10k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
750
Embracing the Ebb and Flow
colly
88
5k
Tell your own story through comics
letsgokoyo
1
800
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Amusing Abliteration
ianozsvald
0
96
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
4 Signs Your Business is Dying
shpigford
187
22k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
Transcript
Integration testing with TestСontainers-Go Erdem Toraman Nikolay Kuznetsov GoDays -
Berlin 23 Jan 2020
About us • Go developers at Zalando in Helsinki •
Project with ~20 microservices in Go • User perspective of TestContainers-Go library
2 unit tests passed, 0 integration tests
Basic integration test
Getting a database for testing • Local database • In-memory
mock • Docker!
Docker advantages • 100% compatible databases • Same version as
production • Empty DB state
Integration testing with Docker
Easy-peasy! docker run -d -p 5432:5432 postgres:12.1
• Host port conflicts • Not ready сontainer / service
• Resource leak (the container keeps running) • Stale data (if reusing the same container) • Starting mechanism both for CI and a local machine What could go wrong?
Solving some issues
None
Docker API docs.docker.com/engine/api/latest
Exec example
None
TestContainers flavors
TestContainers-Go github.com/testcontainers/testcontainers-go • Docker Go client under the hood •
Host port randomization • Containers clean up at the test shutdown • Readiness waiting strategies
As simple as pgContainer, err := tc.GenericContainer(ctx, tc.GenericContainerRequest{ ContainerRequest: tc.ContainerRequest{
Image: "postgres:12.1", ExposedPorts: []string{"5432/tcp"}, }, })
Host port randomization • API to get a host port:
• Prevents port conflicts • Enables parallel builds port, err := pgContainer.MappedPort(ctx, "5432/tcp")
Containers cleanup: Ryuk github.com/testcontainers/moby-ryuk • Ryuk kills containers (networks, volumes)
by labels • TC assigns labels to started containers • TC keeps a connection to Ryuk open
Waiting strategies • Host port • HTTP • Logs •
Custom • Multi
Host port waiting strategy • Default (customizable) timeout is 60
seconds • Impl checks both from outside and inside container tc.ContainerRequest{ Image: "postgres:12.1", ExposedPorts: []string{"5432/tcp"}, WaitingFor: wait.ForListeningPort("5432/tcp"), },
HTTP waiting strategy WaitingFor: wait.ForHTTP("/health"). WithPort("8080/tcp"). WithStatusCodeMatcher( func(status int) bool
{ return status == http.StatusOK }),
Demo
Demo I: integration testing User Repository github.com/erdemtoraman/godays-testcontainers-demo • Testing interaction
with a database • Create and Get users from Postgres
What happened? • Ran a postgres container • Mapped the
port to a random host machine port • Ran tests against it • Cleaned up the container go test ./...
Demo II: end-to-end testing User Service github.com/erdemtoraman/godays-testcontainers-demo Ticket Service Docker
Network Tests HTTP
Takeaways • testcontainers.org • Balance between flexibility, speed and features
• Great for integration tests • Possible to use for end-to-end tests
Thank you! @erdem_toraman, @nikolayk812 erdemtoraman