Hi All, I'm new to WireMock. My application is wi...
# general
k
Hi All, I'm new to WireMock. My application is wirtten in Golang. I know I can use WireMock API to do record&playback in Java, wonder if I can do the same thing in Golang?
o
Hi! You ca use it directly via REST API, but unfortunately Go WireMock does not implement API for it AFAICT. https://pkg.go.dev/github.com/wiremock/go-wiremock. It would be great if you could subit an issue to https://github.com/wiremock/go-wiremock FYI @Ruslan Isamukhametov
k
@Oleg Nenashev Thanks for your answer. You're right, I can use REST API to start/stop record, that mean I have to setup a standalone WireMock server somewhere. But with Java, I can directly create a WireMock server just in my current process and start record from there. This doesn't seem doable in Go.
o
Check out https://github.com/wiremock/wiremock-testcontainers-go . It provisions the instance in the container
... and then you can manage it as needed
a
@Oleg Nenashev Thank you for your responses. Here is what @Kevin Wang and I are trying to accomplish: Our Golang application communicates with a k8s cluster via Kubernetes API. We want: 1. Record the requests/responses via WireMock; 2. Use that data to simulate a k8s cluster to run Unit tests for our application. We are already implemented this functionality for our Java code. Is it possible to do the same for our Golang code?
o
Hî. Yes, it is. WireMock module for Testcontainers Go bundles the full featured WireMock for Java build in the Docker container
k
@Oleg Nenashev thank for the response, when I use
wiremock-testcontainers-go
, I always get a error to pull WireMock image, I know it's due to the docker pull limit. It could be fixed by passing a image pull secret if the container is running in a Kubernetes cluster, but I don't know how to do that with
wiremock-testcontainers-go
, is there a way to pass a secret or docker credentials to get around it?
Copy code
2023/10/25 11:27:08 Failed to pull image: Error response from daemon: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: <https://www.docker.com/increase-rate-limit>, will retry
a
@Kevin Wang I saw this error message before for other pods. Try to delete the pod and pull the image again, it may succeed eventually.
o
So WireMock is not [yet] sponsored on DockerHub. so we have quite strict rate limits for non-authenticated users. With the WireMock module you can use the same ContainerRequest amendment as for Generic containers: https://golang.testcontainers.org/features/docker_auth/
k
Thanks @Oleg Nenashev I used the
DOCKER_AUTH_CONFIG
and pass my docker config file, it works for me. I can see a wiremock container is created on my local. I wonder what if I run it in a pod on a Kubernetes cluster. Will it pull up a separate K8s pod or it only create a container inside the pod?
o
Depends on your K8s configuration. Provisioning WireMock in the sidecar container makes a lot of sense for many cases, less for others
k
Can you be more specific about K8s configuration? I understand we definitely can run WireMock as sidecar container in a Kubernetes pod. but I'm a little hesitant to modify the K8s deployment of my Go application. I still want to explore the other options like testcontainers module, which I can create the WireMock on the fly and clean it up whenever I don't need it.
o
In such a case you can just run standalone instance in a separate POD, that's perfectly fine. If you have some time in the coming weeks I would be interested to jump on a call and take a look at your setup and use cases together, what do you think?
In WireMock we are yet to create detailed guidelines for kubernetes, so it's a good time to discuss use cases and to have them in tickets for the official Helm chart, operator, etc.
a
Hi @Oleg Nenashev Sure, we can have a call and talk about our use case for WireMock.
Specifically, it’s not clear for us at this point how we can integrate the recorded WireMock data with our application Go unit tests.
o
Hi. So basically it would be... 1. Running the test as normally 2. Before shutting down the container instance, querying the communication logs using REST API. https://wiremock.org/docs/standalone/admin-api-reference/#tag/Requests/paths/~1__admin~1requests/get. AFAICT Go WireMock does not implement it, but you can just call REST API (or add a method to Go WireMock) 3. Process the retrieved data