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 TestContainers-Go
Search
Nikolay Kuznetsov
January 23, 2020
Programming
290
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Integration testing with TestContainers-Go
Go Days 2020 - Berlin
Nikolay Kuznetsov
January 23, 2020
More Decks by Nikolay Kuznetsov
See All by Nikolay Kuznetsov
Integration testing with TestСontainers-Go
nikolayk812
0
140
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
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
Next.js: The final boss of Web Performance
guaca
0
260
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
130
JIS keyboard support in Omarchy
lef237
0
120
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
430
phperだってパンチカードでコーディングしたい
o0h
PRO
0
340
AmebaブログはKMPから卒業します
kmars0605
0
190
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
240
contenteditable と日本語入力に向き合う
colorful12
0
200
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
380
Featured
See All Featured
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
360
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Building Adaptive Systems
keathley
44
3.2k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
800
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Raft: Consensus for Rubyists
vanstee
142
7.8k
Odyssey Design
rkendrick25
PRO
2
870
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
560
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
460
Rails Girls Zürich Keynote
gr2m
96
14k
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 a
random port to the host machine • Ran tests against it • Cleaned up the containers
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