Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Integration testing with TestСontainers-Go
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Nikolay Kuznetsov
June 18, 2020
Programming
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Integration testing with TestСontainers-Go
GopherCon Europe 2020 - Lightning talk
Nikolay Kuznetsov
June 18, 2020
More Decks by Nikolay Kuznetsov
See All by Nikolay Kuznetsov
Integration testing with TestContainers-Go
nikolayk812
0
290
Integration testing with TestСontainers and JUnit 5
nikolayk812
0
190
TestContainers + JUnit 5 = elegant integration and e2e tests for microservices
nikolayk812
2
390
Integration and end-to-end testing with TestСontainers
nikolayk812
0
130
Integration and end-to-end testing with TestСontainers
nikolayk812
0
38
Other Decks in Programming
See All in Programming
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
520
[Dev Group Paris Octobre 26] Agentforce, SIforce, Claudeforce, Slackbot… on s'y retrouve ?
nabondance
0
110
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
430
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.2k
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
260
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
430
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
940
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
Featured
See All Featured
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Navigating Weather and Climate Data
rabernat
0
560
Agile that works and the tools we love
rasmusluckow
331
22k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
580
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
Mind Mapping
helmedeiros
1
400
Large-scale JavaScript Application Architecture
addyosmani
516
110k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Transcript
Integration testing with TestСontainers-Go Nikolay Kuznetsov GopherCon Europe 18 Jun
2020 @nikolayk812
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) What could go wrong?
Solving some issues
None
Docker API docs.docker.com/engine/api/latest
Exec example
None
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 • Ryuk acts when the connection is terminated
Waiting strategies • Host port • HTTP • SQL •
Logs • Custom • Multi
Host port waiting strategy • Impl checks both from outside
and inside container • Default (customizable) timeout is 60 seconds 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 }),
Takeaways • testcontainers.org • Balance between flexibility, speed and features
• Great for integration tests • Possible to use for end-to-end tests
Thank you! @nikolayk812 nikolayk812