Gregoire PARIS
08/25/2025, 3:10 PMtest1 when running the first test, then directory test2 when running the second test, etc. etc.
We are using Golang.Mathieu
08/25/2025, 7:34 PMMathieu
08/25/2025, 7:37 PMReuse will ensure you're always getting the same container. Note here that testcontainers will, by default, delete containers it created after 10s of inactivity. You can change that behavior with env vars and/or a config file. See the section about ryuk in their docMathieu
08/25/2025, 7:39 PMGregoire PARIS
08/26/2025, 7:26 AMMathieu
08/26/2025, 2:00 PM/home/wiremock/mappings.Mathieu
08/26/2025, 2:02 PM/__admin/mappings/import endpoint that allows for creating a bunch of stubs at once. Maybe you could leverage that too.
Buuuuut, the golang lib doesn't support it yet. That I can fix!Gregoire PARIS
08/27/2025, 7:54 AMMathieu
08/27/2025, 1:45 PMMathieu
08/27/2025, 1:46 PMGregoire PARIS
08/27/2025, 1:54 PMgo test -v on https://github.com/greg0ire/wiremock-blogpost/tree/bp , the whole test takes 1.86s, and I can feel the 2 steps taking time is:
1. Waiting for the container to be up
2. Stopping the container
=== RUN TestIndexRecord
2025/08/27 15:53:40 github.com/testcontainers/testcontainers-go - Connected to docker:
Server Version: 28.3.3
API Version: 1.48
Operating System: Arch Linux
Total Memory: 27878 MB
Testcontainers for Go Version: v0.37.0
Resolved Docker Host: unix:///var/run/docker.sock
Resolved Docker Socket Path: /var/run/docker.sock
Test SessionID: 06357081b125e2a08bc1b947ad1e5f7a014e956d122f8e58c38e21b9b0ba7389
Test ProcessID: 085b58ee-5919-401e-b86f-680897bdeb88
2025/08/27 15:53:40 π³ Creating container for image wiremock/wiremock:3.12.1
2025/08/27 15:53:40 π³ Creating container for image testcontainers/ryuk:0.11.0
2025/08/27 15:53:40 β
Container created: b0b6eed28c1f
2025/08/27 15:53:40 π³ Starting container: b0b6eed28c1f
2025/08/27 15:53:41 β
Container started: b0b6eed28c1f
2025/08/27 15:53:41 β³ Waiting for container id b0b6eed28c1f image: testcontainers/ryuk:0.11.0. Waiting for: &{Port:8080/tcp timeout:<nil> PollInterval:100ms skipInternalCheck:false}
2025/08/27 15:53:41 π Container is ready: b0b6eed28c1f
2025/08/27 15:53:41 β
Container created: 3cffcee80267
2025/08/27 15:53:41 π³ Starting container: 3cffcee80267
2025/08/27 15:53:41 β
Container started: 3cffcee80267
2025/08/27 15:53:41 β³ Waiting for container id 3cffcee80267 image: wiremock/wiremock:3.12.1. Waiting for: &{timeout:<nil> Port:8080 Path:/__admin StatusCodeMatcher:0x83c5c0 ResponseMatcher:0x896560 UseTLS:false AllowInsecure:false TLSConfig:<nil> Method:GET Body:<nil> Headers:map[] ResponseHeadersMatcher:0x896580 PollInterval:100ms UserInfo: ForceIPv4LocalHost:false}
2025/08/27 15:53:42 π Container is ready: 3cffcee80267
2025/08/27 15:53:42 π³ Stopping container: 3cffcee80267
2025/08/27 15:53:42 β
Container stopped: 3cffcee80267
2025/08/27 15:53:42 π³ Terminating container: 3cffcee80267
2025/08/27 15:53:42 π« Container terminated: 3cffcee80267
--- PASS: TestIndexRecord (1.85s)
PASS
ok algolia-wiremock-testcontainers 1.884sMathieu
08/27/2025, 2:09 PM$ ALGOLIA_APP_ID=foo ALGOLIA_API_KEY=bar go test -v -count 1 .
=== RUN TestIndexRecord
2025/08/27 10:07:47 github.com/testcontainers/testcontainers-go - Connected to docker:
Server Version: 28.3.3
API Version: 1.50
Operating System: OrbStack
Total Memory: 16031 MB
Testcontainers for Go Version: v0.37.0
Resolved Docker Host: unix:///var/run/docker.sock
Resolved Docker Socket Path: /var/run/docker.sock
Test SessionID: 6d838d47ba19e07bdca0987a8df51fc64443a1191fe12f6ccc61ea00d6f96984
Test ProcessID: 2879132d-a7e9-4cd5-8868-233efa4bc993
2025/08/27 10:07:47 π³ Creating container for image wiremock/wiremock:3.12.1
2025/08/27 10:07:47 β
Container created: 305f8898133a
2025/08/27 10:07:47 π³ Starting container: 305f8898133a
2025/08/27 10:07:47 β
Container started: 305f8898133a
2025/08/27 10:07:47 β³ Waiting for container id 305f8898133a image: wiremock/wiremock:3.12.1. Waiting for: &{timeout:<nil> Port:8080 Path:/__admin StatusCodeMatcher:0x104fa0ad0 ResponseMatcher:0x104fee3e0 UseTLS:false AllowInsecure:false TLSConfig:<nil> Method:GET Body:<nil> Headers:map[] ResponseHeadersMatcher:0x104fee3f0 PollInterval:100ms UserInfo: ForceIPv4LocalHost:false}
2025/08/27 10:07:47 π Container is ready: 305f8898133a
2025/08/27 10:07:47 π³ Stopping container: 305f8898133a
2025/08/27 10:07:48 β
Container stopped: 305f8898133a
2025/08/27 10:07:48 π³ Terminating container: 305f8898133a
2025/08/27 10:07:48 π« Container terminated: 305f8898133a
--- PASS: TestIndexRecord (1.25s)
PASS
ok algolia-wiremock-testcontainers 1.502s
Note that I have ryuk disabled so that's probably why it's a bit quicker.Mathieu
08/27/2025, 2:09 PMMathieu
08/27/2025, 2:34 PMMathieu
08/27/2025, 2:36 PM=== RUN TestIndexRecord
2025/08/27 10:33:10 <http://github.com/testcontainers/testcontainers-go|github.com/testcontainers/testcontainers-go> - Connected to docker:
Server Version: 28.3.3
API Version: 1.50
Operating System: OrbStack
Total Memory: 16031 MB
Testcontainers for Go Version: v0.37.0
Resolved Docker Host: unix:///var/run/docker.sock
Resolved Docker Socket Path: /var/run/docker.sock
Test SessionID: 025ae1953c93516e0b8c836a7ca9b9d8969d0b8d45a2ed165c4401d0cc44664f
Test ProcessID: a8ca9de2-fb11-4164-89ef-d96112627b3b
2025/08/27 10:33:10 π³ Creating container for image wiremock/wiremock:3.12.1
2025/08/27 10:33:10 β
Container created: de88eb81855a
2025/08/27 10:33:10 π³ Starting container: de88eb81855a
2025/08/27 10:33:10 β
Container started: de88eb81855a
2025/08/27 10:33:10 β³ Waiting for container id de88eb81855a image: wiremock/wiremock:3.12.1. Waiting for: &{timeout:<nil> Port:8080 Path:/__admin StatusCodeMatcher:0x104668460 ResponseMatcher:0x1046b5b10 UseTLS:false AllowInsecure:false TLSConfig:<nil> Method:GET Body:<nil> Headers:map[] ResponseHeadersMatcher:0x1046b5b20 PollInterval:100ms UserInfo: ForceIPv4LocalHost:false}
2025/08/27 10:33:11 π Container is ready: de88eb81855a
--- PASS: TestIndexRecord (0.76s)
=== RUN TestIndexRecord2
2025/08/27 10:33:11 β
Container started: de88eb81855a
2025/08/27 10:33:11 β³ Waiting for container id de88eb81855a image: wiremock/wiremock:3.12.1. Waiting for: &{timeout:<nil> Port:8080 Path:/__admin StatusCodeMatcher:0x104668460 ResponseMatcher:0x1046b5b10 UseTLS:false AllowInsecure:false TLSConfig:<nil> Method:GET Body:<nil> Headers:map[] ResponseHeadersMatcher:0x1046b5b20 PollInterval:100ms UserInfo: ForceIPv4LocalHost:false}
2025/08/27 10:33:11 π Container is ready: de88eb81855a
--- PASS: TestIndexRecord2 (0.14s)
=== RUN TestIndexRecord3
2025/08/27 10:33:11 β
Container started: de88eb81855a
2025/08/27 10:33:11 β³ Waiting for container id de88eb81855a image: wiremock/wiremock:3.12.1. Waiting for: &{timeout:<nil> Port:8080 Path:/__admin StatusCodeMatcher:0x104668460 ResponseMatcher:0x1046b5b10 UseTLS:false AllowInsecure:false TLSConfig:<nil> Method:GET Body:<nil> Headers:map[] ResponseHeadersMatcher:0x1046b5b20 PollInterval:100ms UserInfo: ForceIPv4LocalHost:false}
2025/08/27 10:33:11 π Container is ready: de88eb81855a
--- PASS: TestIndexRecord3 (0.15s)
=== RUN TestIndexRecord4
2025/08/27 10:33:11 β
Container started: de88eb81855a
2025/08/27 10:33:11 β³ Waiting for container id de88eb81855a image: wiremock/wiremock:3.12.1. Waiting for: &{timeout:<nil> Port:8080 Path:/__admin StatusCodeMatcher:0x104668460 ResponseMatcher:0x1046b5b10 UseTLS:false AllowInsecure:false TLSConfig:<nil> Method:GET Body:<nil> Headers:map[] ResponseHeadersMatcher:0x1046b5b20 PollInterval:100ms UserInfo: ForceIPv4LocalHost:false}
2025/08/27 10:33:11 π Container is ready: de88eb81855a
--- PASS: TestIndexRecord4 (0.15s)
=== RUN TestIndexRecord5
2025/08/27 10:33:11 β
Container started: de88eb81855a
2025/08/27 10:33:11 β³ Waiting for container id de88eb81855a image: wiremock/wiremock:3.12.1. Waiting for: &{timeout:<nil> Port:8080 Path:/__admin StatusCodeMatcher:0x104668460 ResponseMatcher:0x1046b5b10 UseTLS:false AllowInsecure:false TLSConfig:<nil> Method:GET Body:<nil> Headers:map[] ResponseHeadersMatcher:0x1046b5b20 PollInterval:100ms UserInfo: ForceIPv4LocalHost:false}
2025/08/27 10:33:11 π Container is ready: de88eb81855a
--- PASS: TestIndexRecord5 (0.16s)
PASS
ok algolia-wiremock-testcontainers 1.587s
Notice the container is only started once. Now it is not deleted afterwards, but that's what ryuk is for.
I'm using a hash of absolutePath in the container name to ensure that a new container would be created for a different file.Gregoire PARIS
08/27/2025, 2:39 PMGregoire PARIS
08/27/2025, 2:40 PMabsolutePath for every test, sadly. Will check with them.Mathieu
08/27/2025, 2:51 PMGregoire PARIS
08/27/2025, 2:57 PMGregoire PARIS
08/27/2025, 2:58 PMAntoine Bousquet
08/27/2025, 2:59 PMStubFor / Reset between each test.Antoine Bousquet
08/27/2025, 3:00 PMAntoine Bousquet
08/27/2025, 3:01 PMStubFor equivalent that could work with a JSON string or a JSON file.Antoine Bousquet
08/27/2025, 3:02 PMgo-wiremock ?Gregoire PARIS
08/27/2025, 3:08 PMgo-wiremock ?
Maybe⦠is there an API route you could call for that?Gregoire PARIS
08/27/2025, 3:14 PM/__admin/mappings/importAntoine Bousquet
08/27/2025, 3:19 PMAntoine Bousquet
08/27/2025, 3:20 PMStufForFromJSON(json string) that would accept a JSON string and call StubFor with the deserialized JSONAntoine Bousquet
08/27/2025, 3:20 PMStubForFromJSONFile(jsonPath string) that would accept a JSON file path and call StubForFromJSON with the file contentAntoine Bousquet
08/27/2025, 3:21 PMGregoire PARIS
08/27/2025, 3:25 PMStubForFromJSON yourself, right?Antoine Bousquet
08/27/2025, 3:29 PMGregoire PARIS
08/27/2025, 3:41 PM