func TestCreateArticle(t *testing.T) {
	testRouter := SetupRouter()
	var form forms.CreateArticleForm
	form.Title = "Testing article title"
	form.Content = "Testing article content"
	data, _ := json.Marshal(form)
	req, err := http.NewRequest("POST", "/v1/article", bytes.NewBufferString(string(data)))
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", fmt.Sprintf("Bearer: %s", accessToken))
	if err != nil {
		fmt.Println(err)
	}
	resp := httptest.NewRecorder()
	testRouter.ServeHTTP(resp, req)
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	var res struct {
		Status int
		ID     int
	}
	json.Unmarshal(body, &res)
	articleID = res.ID
	assert.Equal(t, resp.Code, http.StatusOK)
}
TestCreateArticle
Test article creation

Must return response code 200
package tests
import (
	"bytes"
	"encoding/json"
	"fmt"
	"os"
	"io/ioutil"
	"log"
	"net/http"
	"net/http/httptest"
	"testing"
	"github.com/Massad/gin-boilerplate/controllers"
	"github.com/Massad/gin-boilerplate/db"
	"github.com/Massad/gin-boilerplate/forms"
	"github.com/joho/godotenv"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"github.com/stretchr/testify/assert"
)
var auth = new(controllers.AuthController)
func TokenAuthMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		auth.TokenValid(c)
		c.Next()
	}
}
func SetupRouter() *gin.Engine {
	r := gin.Default()
	gin.SetMode(gin.TestMode)
	binding.Validator = new(forms.DefaultValidator)
	v1 := r.Group("/v1")
	{
		user := new(controllers.UserController)
		v1.POST("/user/login", user.Login)
		v1.POST("/user/register", user.Register)
		v1.GET("/user/logout", user.Logout)
		auth := new(controllers.AuthController)
		v1.POST("/token/refresh", auth.Refresh)
		article := new(controllers.ArticleController)
		v1.POST("/article", TokenAuthMiddleware(), article.Create)
		v1.GET("/articles", TokenAuthMiddleware(), article.All)
		v1.GET("/article/:id", TokenAuthMiddleware(), article.One)
		v1.PUT("/article/:id", TokenAuthMiddleware(), article.Update)
		v1.DELETE("/article/:id", TokenAuthMiddleware(), article.Delete)
	}
	return r
}
func main() {
	r := SetupRouter()
	r.Run()
}
var loginCookie string
var testEmail = "test-gin-boilerplate@test.com"
var testPassword = "123456"
var accessToken string
var refreshToken string
var articleID int
func TestIntDB(t *testing.T) {
	err := godotenv.Load("../.env")
	if err != nil {
		log.Fatal("Error loading .env file, please create one in the root directory")
	}
	fmt.Println("DB_PASS", os.Getenv("DB_PASS"))
	db.Init()
	db.InitRedis(1)
}
func TestRegister(t *testing.T) {
	testRouter := SetupRouter()
	var registerForm forms.RegisterForm
	registerForm.Name = "testing"
	registerForm.Email = testEmail
	registerForm.Password = testPassword
	data, _ := json.Marshal(registerForm)
	req, err := http.NewRequest("POST", "/v1/user/register", bytes.NewBufferString(string(data)))
	req.Header.Set("Content-Type", "application/json")
	if err != nil {
		fmt.Println(err)
	}
	resp := httptest.NewRecorder()
	testRouter.ServeHTTP(resp, req)
	assert.Equal(t, resp.Code, http.StatusOK)
}
func TestRegisterInvalidEmail(t *testing.T) {
	testRouter := SetupRouter()
	var registerForm forms.RegisterForm
	registerForm.Name = "testing"
	registerForm.Email = "invalid@email"
	registerForm.Password = testPassword
	data, _ := json.Marshal(registerForm)
	req, err := http.NewRequest("POST", "/v1/user/register", bytes.NewBufferString(string(data)))
	req.Header.Set("Content-Type", "application/json")
	if err != nil {
		fmt.Println(err)
	}
	resp := httptest.NewRecorder()
	testRouter.ServeHTTP(resp, req)
	assert.Equal(t, resp.Code, http.StatusNotAcceptable)
}
func TestLogin(t *testing.T) {
	testRouter := SetupRouter()
	var loginForm forms.LoginForm
	loginForm.Email = testEmail
	loginForm.Password = testPassword
	data, _ := json.Marshal(loginForm)
	req, err := http.NewRequest("POST", "/v1/user/login", bytes.NewBufferString(string(data)))
	req.Header.Set("Content-Type", "application/json")
	if err != nil {
		fmt.Println(err)
	}
	resp := httptest.NewRecorder()
	testRouter.ServeHTTP(resp, req)
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	var res struct {
		Message string `json:"message"`
		User    struct {
			CreatedAt int64  `json:"created_at"`
			Email     string `json:"email"`
			ID        int64  `json:"id"`
			Name      string `json:"name"`
			UpdatedAt int64  `json:"updated_at"`
		} `json:"user"`
		Token struct {
			AccessToken  string `json:"access_token"`
			RefreshToken string `json:"refresh_token"`
		} `json:"token"`
	}
	json.Unmarshal(body, &res)
	accessToken = res.Token.AccessToken
	refreshToken = res.Token.RefreshToken
	assert.Equal(t, resp.Code, http.StatusOK)
}
func TestInvalidLogin(t *testing.T) {
	testRouter := SetupRouter()
	var loginForm forms.LoginForm
	loginForm.Email = "wrong@email.com"
	loginForm.Password = testPassword
	data, _ := json.Marshal(loginForm)
	req, err := http.NewRequest("POST", "/v1/user/login", bytes.NewBufferString(string(data)))
	req.Header.Set("Content-Type", "application/json")
	if err != nil {
		fmt.Println(err)
	}
	resp := httptest.NewRecorder()
	testRouter.ServeHTTP(resp, req)
	assert.Equal(t, resp.Code, http.StatusNotAcceptable)
}