Skip to content

Help with go coverage #1924

Answered by PranshuSrivastava
srinikom asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @srinikom, the go tool requires graceful shutdown in the application because it calculates the coverage after receiving the sigint signal. That was missing in the application and that is why we are getting 0 coverage. You can try using this in the server/server.go file, and it should give you the coverage.

package server

import (
	"time"
	"github.com/keploy/gin-redis/routes"
	"os"
	"context"
	"fmt"
	"net/http"
	"os/signal"
	"syscall"
)

func Init() {
	r := routes.NewRouter()
	port := "3001"
	srv := &http.Server{
		Addr:   ":" + port,
		Handler: r,
	}
	go func() {
		if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
			fmt.Printf("listen: %s\n", err)
		}
	}()
	G…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Sonichigo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants