You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
886 B
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package utils
import (
"miniapp/model/common/request"
"testing"
)
type PageInfoTest struct {
PageInfo request.PageInfo
Name string
}
func TestVerify(t *testing.T) {
PageInfoVerify := Rules{"Page": {NotEmpty()}, "PageSize": {NotEmpty()}, "Name": {NotEmpty()}}
var testInfo PageInfoTest
testInfo.Name = "test"
testInfo.PageInfo.Page = 0
testInfo.PageInfo.PageSize = 0
err := Verify(testInfo, PageInfoVerify)
if err == nil {
t.Error("校验失败未能捕捉0值")
}
testInfo.Name = ""
testInfo.PageInfo.Page = 1
testInfo.PageInfo.PageSize = 10
err = Verify(testInfo, PageInfoVerify)
if err == nil {
t.Error("校验失败未能正常检测name为空")
}
testInfo.Name = "test"
testInfo.PageInfo.Page = 1
testInfo.PageInfo.PageSize = 10
err = Verify(testInfo, PageInfoVerify)
if err != nil {
t.Error("校验失败,未能正常通过检测")
}
}