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
Integration testing with TestСontainers-Go
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Nikolay Kuznetsov
June 18, 2020
Programming
0
130
Integration testing with TestСontainers-Go
GopherCon Europe 2020 - Lightning talk
Nikolay Kuznetsov
June 18, 2020
Tweet
Share
More Decks by Nikolay Kuznetsov
See All by Nikolay Kuznetsov
Integration testing with TestContainers-Go
nikolayk812
0
260
Integration testing with TestСontainers and JUnit 5
nikolayk812
0
170
TestContainers + JUnit 5 = elegant integration and e2e tests for microservices
nikolayk812
2
350
Integration and end-to-end testing with TestСontainers
nikolayk812
0
120
Integration and end-to-end testing with TestСontainers
nikolayk812
0
29
Other Decks in Programming
See All in Programming
Oxlint JS plugins
kazupon
1
960
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
200
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.3k
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
CSC307 Lecture 01
javiergs
PRO
0
690
Oxlintはいいぞ
yug1224
5
1.3k
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
710
今から始めるClaude Code超入門
448jp
8
8.8k
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
130
CSC307 Lecture 05
javiergs
PRO
0
500
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
750
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
270
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.1k
BBQ
matthewcrist
89
10k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
170
GraphQLの誤解/rethinking-graphql
sonatard
74
11k
Rails Girls Zürich Keynote
gr2m
96
14k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
350
Statistics for Hackers
jakevdp
799
230k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
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