/
githubmirror
/
GoFrame
Обзор
Документация
Войти
/
githubmirror
/
GoFrame
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
util/gvalid/gvalid_z_unit_feature_meta_test.go
47 строк
1 KB
John Guo
fix issue in rules of gmeta.Meta for package gvalid
18 янв 2022, 10:43
18 янв 2022, 10:43
033e2c1
Код
Авторство
О чём код?
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. // // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. package gvalid_test import ( "context" "testing" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/test/gtest" "github.com/gogf/gf/v2/util/gvalid" ) type UserCreateReq struct { g.Meta `v:"UserCreateReq"` Name string Pass string } func RuleUserCreateReq(ctx context.Context, in gvalid.RuleFuncInput) error { var req *UserCreateReq if err := in.Data.Scan(&req); err != nil { return gerror.Wrap(err, `Scan data to UserCreateReq failed`) } return gerror.Newf(`The name "%s" is already token by others`, req.Name) } func Test_Meta(t *testing.T) { var user = &UserCreateReq{ Name: "john", Pass: "123456", } gtest.C(t, func(t *gtest.T) { err := g.Validator().RuleFunc("UserCreateReq", RuleUserCreateReq). Data(user). Assoc(g.Map{ "Name": "john smith", }).Run(ctx) t.Assert(err.String(), `The name "john smith" is already token by others`) }) }