How to use mocking for testing the GetTables function without creating the real database connection?

28 Views Asked by At
func GetTables(pool *pgxpool.Pool, session *session.Store, enforcer *casbin.Enforcer) fiber.Handler {

    rows, err := pool.Query(context.Background(), "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")
            if err != nil {
                return err
            }
            defer rows.Close()

            var tables []string

            for rows.Next() {
                var tableName string
                if err := rows.Scan(&tableName); err != nil {
                    return err
                }
                tables = append(tables, tableName)
            }

            err = ctx.JSON(tables)
            if err != nil {
                panic("Error occurred when returning users JSON: " + err.Error())
            }
            return err
        }
        return nil
    }

}

so how can i achieve the mocking here so if anybody can help me to write the test function for it then it would be very useful for me

0

There are 0 best solutions below