stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
23.15k stars 1.59k forks source link

use of mock #1490

Closed anuragvaru closed 10 months ago

anuragvaru commented 11 months ago

Hi I am new to golang and want to use unit testing to test the code. so that code->function

func CheckTwoFactor(dbpool *pgxpool.Pool) fiber.Handler{
    return func(ctx *fiber.Ctx) error {
        userId :=ctx.FormValue("id")
        fmt.Println(userId)
        userID, _ := strconv.Atoi(userId)
        User,err:=FindUserByID(dbpool,int64(userID))
        if err != nil {
            log.Fatalf("Error when finding user by ID: %v", err)
        }
        fmt.Println(User)
        if !User.Two_factor{
            return ctx.JSON(fiber.Map{
                "result":false,
            })
        }else{
            return ctx.JSON(fiber.Map{
                "result":true,
            })
        }
}
}

how can i use mock in that can any one please help me to reach it's solutiion

dolmen commented 10 months ago

This isn't a support forum. Please start to work on the task by yourself, and then ask your question elsewhere.