Skip to main content

All Questions

Tagged with
-2 votes
0 answers
30 views

Golang test cases for gin failing [closed]

Hi All I am trying to create a test cases for my gin gonic framework where I am using Gorm and ORM but I am getting errors like this: [31m2024/07/03 08:48:19 [Recovery] 2024/07/03 - 08:48:19 panic ...
Nilay Singh's user avatar
  • 2,287
1 vote
1 answer
62 views

Error on testing Gingko and Gomega for gingonic, w.Code not working

I have some tests written in Ginkgo that check the return-code, a 502 code should be returned at a specific moment in time, it returns 502 (as you can see on the logs) but the w.Code is still 200. [...
LombardiD's user avatar
  • 341
1 vote
0 answers
77 views

How to effectively organize tests for Gin/GORM based web-apps?

I am quite new to web development in Golang using Gin/GORM and I am currently struggling to find out the best practice to organize packages and unit-tests. The problem arises from the fact I would ...
wandering-tales's user avatar
3 votes
2 answers
1k views

How to unit test gin handlers for correct validation of uri params?

I need to test a set of gin handlers with dependencies. I have some successful unit tests up and running, mocking the gin context. I notice, however, that ShouldBindURI never works. The key passed to ...
Laura's user avatar
  • 337
1 vote
0 answers
710 views

Golang Test EOF after client.Do(req)

I am using an application using the Gin framework. I am writing a test for one of my handlers: package controllers import ( "bytes" "encoding/json" "github.com/...
Majid Alaeinia's user avatar
0 votes
1 answer
2k views

Go gin nested JSON request body POST, error unexpected end of JSON input

I am new to GO and was trying to create a simple POST API with gin and gorm. The request data is nested JSON like below: { "fall_orders_request": [ { "fruit": "...
Valhala's user avatar
  • 21
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 ...
fabian heredia's user avatar
1 vote
1 answer
1k views

Why my test with Gin and Go is not passing?

I am trying to test my API. In this case, I have this main file: package main import ( "fmt" "net/http" "github.com/gin-gonic/gin" ) func main() { r := ...
kike's user avatar
  • 718
11 votes
3 answers
10k views

Programmatically set an url parameter in gin context for testing purpose

I am writing some test suites for gin middlewares. I found a solution to test them without having to run a full router engine, by creating a gin context like this : w := httptest.NewRecorder() c, _ := ...
KawaLo's user avatar
  • 2,135
0 votes
2 answers
913 views

How to test form submission

I have a login form with some html that users fill in: <form method="post" enctype="multipart/form-data"> <div class="form"><input name="username"> </div> <...
shbfy's user avatar
  • 2,105
13 votes
2 answers
20k views

Unit Testing With Gin-Gonic

My project is split into three main components: controllers, services, and models. When a route is queried via the URI, the controllers are called, which then call the services to interact with the ...
Evan Bloemer's user avatar
  • 1,071
1 vote
1 answer
3k views

How to create gin.Context from *http.Request and *httptest.ResponseRecorder?

I would like to create a test helper for gin similar to testify's HTTPBodyContain. I am having a hard time creating gin.Context from *http.Request and *httptest.ResponseRecorder. I've already written ...
Patryk's user avatar
  • 23.7k
0 votes
1 answer
1k views

How to test main function in gin application?

How can I test func main? Like this: func main(){ Engine := GetEngine() // returns gin router with handlers atttached Engine.Run(":8080") } It has only 2 lines but I'd like to have them ...
Eugene Lisitsky's user avatar
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 ...
Wilson Tamarozzi's user avatar
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. ...
Jenny Blunt's user avatar
  • 1,586

15 30 50 per page