-
Notifications
You must be signed in to change notification settings - Fork 3
/
easy-admin_test.go
40 lines (34 loc) · 930 Bytes
/
easy-admin_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/nicelizhi/easy-admin/app/admin/apis"
"github.com/stretchr/testify/assert"
)
func HomepageHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Welcome golang"})
}
func SetUpRouter() *gin.Engine {
gin.SetMode(gin.TestMode)
router := gin.Default()
fmt.Println(router.Routes())
return router
}
func TestHomepageHandler(t *testing.T) {
// mockResponse := `{"message":"Welcome goland"}`
r := SetUpRouter()
r.GET("/", apis.EasyAdminStart)
req, _ := http.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
// responseData, _ := ioutil.ReadAll(w.Body)
// assert.Equal(t, mockResponse, string(responseData))
assert.Equal(t, http.StatusOK, w.Code)
}
func TestUserLoginHandler(t *testing.T) {
// r := SetUpRouter()
// r.GET("/api/v1/getinfo", apis.SysUser.GetInfo)
}