I have searched everywhere for information on how to resolve this issue. I am not getting full coverage on testing of a Gin GET call in Go.
I am calling the test and the results are at 50% for the function and i cannot seem to get the results to 100%.
Here is the code and the coverage output html
This is the Go code
var JSONGET = func(c *gin.Context) {
c.IndentedJSON(http.StatusOK, gin.H{
"code": http.StatusOK,
"endpoint": c.Request.RequestURI,
"response": gin.H{
"body": "GET Response",
"type": "text",
},
"status": "http.StatusOK",
"type": "GET",
})
}
// PingGET ...
func PingGET(c *gin.Context) gin.HandlerFunc {
return JSONGET
}
This is the test function
func TestPingGET(t *testing.T) {
response := httptest.NewRecorder()
context, _ := gin.CreateTestContext(response)
fmt.Println(response.Code)
PingGET(context)
fmt.Println(response.Code)
if response.Code != http.StatusOK {
t.Errorf("Error PingGET failed")
}
}
Here is the output html but you will need to view the picture for more clarification about which are the parts that aren't being tested.
package handler
import (
"net/http"
"github.com/gin-gonic/gin"
)
// JSONGET ...
var JSONGET = func(c *gin.Context) **{
c.IndentedJSON(http.StatusOK, gin.H{
"code": http.StatusOK,
"endpoint": c.Request.RequestURI,
"response": gin.H{
"body": "GET Response",
"type": "text",
},
"status": "http.StatusOK",
"type": "GET",
})
}**
// PingGET ...
func PingGET(c *gin.Context) gin.HandlerFunc {
return JSONGET
}
If anyone can explain how to resolve this and/or explain this?
Aucun commentaire:
Enregistrer un commentaire