Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6fe7fc2

Browse files
authored
feat: add validation for list(string) (#114)
* feat: add validation for list(string)* fix
1 parent23a23a2 commit6fe7fc2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

‎provider/parameter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ func (v *Validation) Valid(typ, value string) error {
390390
ifv.Monotonic!=""&&v.Monotonic!=ValidationMonotonicIncreasing&&v.Monotonic!=ValidationMonotonicDecreasing {
391391
returnfmt.Errorf("number monotonicity can be either %q or %q",ValidationMonotonicIncreasing,ValidationMonotonicDecreasing)
392392
}
393+
case"list(string)":
394+
varlistOfStrings []string
395+
err:=json.Unmarshal([]byte(value),&listOfStrings)
396+
iferr!=nil {
397+
returnfmt.Errorf("value %q is not valid list of strings",value)
398+
}
393399
}
394400
returnnil
395401
}

‎provider/parameter_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,19 @@ func TestValueValidatesType(t *testing.T) {
514514
Min:0,
515515
Max:2,
516516
Monotonic:"decreasing",
517+
}, {
518+
Name:"ValidListOfStrings",
519+
Type:"list(string)",
520+
Value:`["first","second","third"]`,
521+
}, {
522+
Name:"InvalidListOfStrings",
523+
Type:"list(string)",
524+
Value:`["first","second","third"`,
525+
Error:regexp.MustCompile("is not valid list of strings"),
526+
}, {
527+
Name:"EmptyListOfStrings",
528+
Type:"list(string)",
529+
Value:`[]`,
517530
}} {
518531
tc:=tc
519532
t.Run(tc.Name,func(t*testing.T) {
@@ -529,6 +542,8 @@ func TestValueValidatesType(t *testing.T) {
529542
iftc.Error!=nil {
530543
require.Error(t,err)
531544
require.True(t,tc.Error.MatchString(err.Error()),"got: %s",err.Error())
545+
}else {
546+
require.NoError(t,err)
532547
}
533548
})
534549
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp