Skip to content

Commit

Permalink
✅ test: add a test case for the issues #246
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 5, 2024
1 parent e57b4eb commit 372b694
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,48 @@ func TestIssues_223(t *testing.T) {
assert.StrContains(t, s, "clinics.*.doctors.*.duration value must be an integer")
}

// issues#246 类似这样的结构体和规则
type CertStore struct {
Type string `form:"type" json:"type"`
Domains []string `form:"domains" json:"domains"`
AutoRenew bool `form:"auto_renew" json:"auto_renew"`
UserID uint `form:"user_id" json:"user_id" filter:"uint"`
DNSID uint `form:"dns_id" json:"dns_id" filter:"uint"`
WebsiteID uint `form:"website_id" json:"website_id" filter:"uint"`
}

func (r *CertStore) Rules() map[string]string {
return map[string]string{
"type": "required|in:P256,P384,2048,4096",
"domains": "required|array",
"auto_renew": "required|bool",
"user_id": "required|uint|exists:cert_users,id",
"dns_id": "uint",
"website_id": "uint",
}
}

// https://github.com/gookit/validate/issues/246
// 使用 uint filter时,传 null 值会报错 convert value type error
func TestIssues_246(t *testing.T) {
jsonStr := `{
"domains": [],
"dns_id": null,
"type": "P256",
"user_id": null,
"website_id": null,
"auto_renew": true
}`
cs := &CertStore{}
err := jsonutil.DecodeString(jsonStr, cs)
assert.NoErr(t, err)
dump.P(cs)

v := validate.Struct(cs)
assert.True(t, v.Validate())
dump.P(cs)
}

type mockUUID [16]byte

type TestUser struct {
Expand Down

0 comments on commit 372b694

Please sign in to comment.