mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-27 01:51:56 +08:00
Test: model.Tags / modifications
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// HashID 将给定文件的HashID转换为真实ID
|
||||
// HashID 将给定对象的HashID转换为真实ID
|
||||
func HashID(IDType int) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if c.Param("id") != "" {
|
||||
50
middleware/hashid_test.go
Normal file
50
middleware/hashid_test.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/HFO4/cloudreve/pkg/hashid"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHashID(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
rec := httptest.NewRecorder()
|
||||
TestFunc := HashID(hashid.FolderID)
|
||||
|
||||
// 未给定ID对象,跳过
|
||||
{
|
||||
c, _ := gin.CreateTestContext(rec)
|
||||
c.Params = []gin.Param{}
|
||||
c.Request, _ = http.NewRequest("POST", "/api/v3/file/dellete/1", nil)
|
||||
TestFunc(c)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
asserts.False(c.IsAborted())
|
||||
}
|
||||
|
||||
// 给定ID,解析失败
|
||||
{
|
||||
c, _ := gin.CreateTestContext(rec)
|
||||
c.Params = []gin.Param{
|
||||
{"id", "2333"},
|
||||
}
|
||||
c.Request, _ = http.NewRequest("POST", "/api/v3/file/dellete/1", nil)
|
||||
TestFunc(c)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
asserts.True(c.IsAborted())
|
||||
}
|
||||
|
||||
// 给定ID,解析成功
|
||||
{
|
||||
c, _ := gin.CreateTestContext(rec)
|
||||
c.Params = []gin.Param{
|
||||
{"id", hashid.HashID(1, hashid.FolderID)},
|
||||
}
|
||||
c.Request, _ = http.NewRequest("POST", "/api/v3/file/dellete/1", nil)
|
||||
TestFunc(c)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
asserts.False(c.IsAborted())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user