Cloudreve/middleware/mock_test.go

38 lines
732 B
Go
Raw Normal View History

2019-12-03 16:32:23 +08:00
package middleware
2019-12-03 21:25:10 +08:00
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/cloudreve/Cloudreve/v3/pkg/util"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
2019-12-03 21:25:10 +08:00
)
2019-12-03 16:32:23 +08:00
func TestMockHelper(t *testing.T) {
2019-12-03 21:25:10 +08:00
asserts := assert.New(t)
MockHelperFunc := MockHelper()
rec := httptest.NewRecorder()
c, _ := gin.CreateTestContext(rec)
c.Request, _ = http.NewRequest("GET", "/test", nil)
2019-12-03 16:32:23 +08:00
2019-12-03 21:25:10 +08:00
// 写入session
{
SessionMock["test"] = "pass"
Session("test")(c)
MockHelperFunc(c)
asserts.Equal("pass", util.GetSession(c, "test").(string))
}
// 写入context
{
ContextMock["test"] = "pass"
MockHelperFunc(c)
test, exist := c.Get("test")
asserts.True(exist)
asserts.Equal("pass", test.(string))
}
2019-12-03 16:32:23 +08:00
}