All Questions
8
questions
1
vote
1
answer
100
views
How to mock a no response from server with Gin Golang
I'm mocking a server for testing my application. I built the mocked server with Golang and Gin. It works well for successful cases.
But one of the cases I want to test is how the application behaves ...
4
votes
0
answers
3k
views
Testify mock ExpectedCall does not match expected call in gin handler, panics
I'm using gin-gonic for a server, and testify for testing and mocks, along with "testing" and "net/http/httptest"
The part of the interface that mocks the method:
func (m *...
4
votes
1
answer
1k
views
DB mock using sqlmock not working for testing Gin/GORM API?
I've an API written using Gin that uses GORM for ORM. The API works perfectly fine when using a real DB and accessing the API URL from the web browser. But I can't get a mocked unit test to pass:
func ...
3
votes
2
answers
4k
views
How to mock a gin.Context?
Hi I've been trying to mock a gin.Context but I have not been able to make it work
I was trying what they did in this solution but it does not work with my router this is the error I have been getting
...
3
votes
1
answer
4k
views
How to set a host on gin's test context?
I would like to write a unit test for a controller but I keep getting a runtime error. I found out that it is due to the absence of the Host on the request, the ClientIP() method and request body. How ...
0
votes
1
answer
2k
views
How to pass json data as request parameter while mocking using gin framework
I have a function to create user which is working properly. Now I have to mock Prepare and SaveUser function inside CreateUser. But that CreateUser require json data as request parameter.
Below is my ...
29
votes
4
answers
44k
views
Make mock gin.Context
I'm writing a REST API using Gin framework. But I was faced a trouble testing my controllers and researching TDD and Mock. I tried to apply TDD and Mock to my code but I could not.
I created a very ...
3
votes
2
answers
4k
views
Mocking functions in Golang to test my http routes
I'm totally confused figuring out how I can mock a function, without using any additional packages like golang/mock. I'm just trying to learn how to do so but can't find many decent online resources.
...