mirror of
https://github.com/cloudreve/cloudreve.git
synced 2025-10-27 18:44:44 +08:00
Test: SessionAuthCheck
This commit is contained in:
24
middleware/mock.go
Normal file
24
middleware/mock.go
Normal file
@ -0,0 +1,24 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"cloudreve/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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user