2019-11-12 03:53:32 -05:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
2020-11-21 04:34:55 -05:00
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/util"
|
2019-11-12 03:53:32 -05:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SessionMock 测试时模拟Session
|
|
|
|
var SessionMock = make(map[string]interface{})
|
|
|
|
|
|
|
|
// ContextMock 测试时模拟Context
|
|
|
|
var ContextMock = make(map[string]interface{})
|
|
|
|
|
|
|
|
// MockHelper 单元测试助手中间件
|
|
|
|
func MockHelper() gin.HandlerFunc {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
// 将SessionMock写入会话
|
|
|
|
util.SetSession(c, SessionMock)
|
|
|
|
for key, value := range ContextMock {
|
|
|
|
c.Set(key, value)
|
|
|
|
}
|
|
|
|
c.Next()
|
|
|
|
}
|
|
|
|
}
|