Cloudreve/middleware/mock.go
Loyalsoldier 79b8784934
Comply with Golang semantic import versioning (#630)
* Code: compatible with semantic import versioning

* Tools & Docs: compatible with semantic import versioning

* Clean go.mod & go.sum
2020-11-21 17:34:55 +08:00

24 lines
534 B
Go

package middleware
import (
"github.com/cloudreve/Cloudreve/v3/pkg/util"
"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()
}
}