优化单元测试

This commit is contained in:
白茶清欢 2025-01-24 15:52:29 +08:00
parent a69f3a1e01
commit 44e6c5cdcf

View File

@ -27,6 +27,7 @@ func TestDefaultValidateRuleGenerateFunc(t *testing.T) {
ParamList: nil,
})
So(err, ShouldBeError)
So(define.IsErr(err, define.ErrValidatorRuleIsEmpty.Error()), ShouldBeTrue)
So(res, ShouldBeEmpty)
})
Convey("传入规则无参数", t, func() {
@ -43,6 +44,7 @@ func TestDefaultValidateRuleGenerateFunc(t *testing.T) {
ParamList: nil,
})
So(err, ShouldBeError)
So(define.IsErr(err, define.ErrValidatorRuleParamCntIsTooLess.Error()), ShouldBeTrue)
So(res, ShouldEqual, "")
})
Convey("传入oneof枚举值构建成功", t, func() {
@ -59,6 +61,7 @@ func TestDefaultValidateRuleGenerateFunc(t *testing.T) {
ParamList: []any{},
})
So(err, ShouldNotBeNil)
So(define.IsErr(err, define.ErrValidatorRuleParamCntIsTooLess.Error()), ShouldBeTrue)
So(res, ShouldBeEmpty)
})
Convey("传入RequiredIf枚举值 -> 参数奇数个", t, func() {
@ -67,6 +70,7 @@ func TestDefaultValidateRuleGenerateFunc(t *testing.T) {
ParamList: []any{1, 2, 3},
})
So(err, ShouldNotBeNil)
So(define.IsErr(err, define.ErrValidatorRuleParamCntIsNotEven.Error()), ShouldBeTrue)
So(res, ShouldBeEmpty)
})
Convey("传入RequiredIf枚举值 -> 构建成功", t, func() {