Skip to content

Commit 13c8231

Browse files
emilien-pugetdaveshanley
authored andcommitted
more tests
1 parent 13f18e4 commit 13c8231

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

parameters/query_parameters_test.go

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ paths:
6969
assert.Nil(t, errors)
7070
}
7171

72-
func TestNewValidator_QueryParamMinimum(t *testing.T) {
72+
func TestNewValidator_QueryParamMinimum_violation(t *testing.T) {
7373
spec := `openapi: 3.1.0
7474
paths:
7575
/a/fishy/on/a/dishy:
@@ -99,6 +99,36 @@ paths:
9999
assert.Equal(t, "Query parameter 'fishy' failed to validate", errors[0].Message)
100100
}
101101

102+
func TestNewValidator_QueryParamMinimum(t *testing.T) {
103+
spec := `openapi: 3.1.0
104+
paths:
105+
/a/fishy/on/a/dishy:
106+
get:
107+
parameters:
108+
- name: fishy
109+
in: query
110+
required: true
111+
schema:
112+
type: string
113+
minLength: 4
114+
operationId: locateFishy
115+
`
116+
117+
doc, err := libopenapi.NewDocument([]byte(spec))
118+
require.NoError(t, err)
119+
m, errs := doc.BuildV3Model()
120+
require.Len(t, errs, 0)
121+
122+
v := NewParameterValidator(&m.Model)
123+
124+
request, _ := http.NewRequest(http.MethodGet, "https://things.com/a/fishy/on/a/dishy?fishy=salmon", nil)
125+
126+
valid, errors := v.ValidateQueryParams(request)
127+
assert.True(t, valid)
128+
129+
assert.Nil(t, errors)
130+
}
131+
102132
func TestNewValidator_QueryParamPost(t *testing.T) {
103133
spec := `openapi: 3.1.0
104134
paths:
@@ -401,6 +431,36 @@ paths:
401431

402432
v := NewParameterValidator(&m.Model)
403433

434+
request, _ := http.NewRequest(http.MethodGet, "https://things.com/a/fishy/on/a/dishy?fishy=300", nil)
435+
436+
valid, errors := v.ValidateQueryParams(request)
437+
assert.True(t, valid)
438+
439+
assert.Nil(t, errors)
440+
}
441+
442+
func TestNewValidator_QueryParamMinimumNumber_violation(t *testing.T) {
443+
spec := `openapi: 3.1.0
444+
paths:
445+
/a/fishy/on/a/dishy:
446+
get:
447+
parameters:
448+
- name: fishy
449+
in: query
450+
required: true
451+
schema:
452+
type: number
453+
minimum: 200
454+
operationId: locateFishy
455+
`
456+
457+
doc, err := libopenapi.NewDocument([]byte(spec))
458+
require.NoError(t, err)
459+
m, errs := doc.BuildV3Model()
460+
require.Len(t, errs, 0)
461+
462+
v := NewParameterValidator(&m.Model)
463+
404464
request, _ := http.NewRequest(http.MethodGet, "https://things.com/a/fishy/on/a/dishy?fishy=123", nil)
405465

406466
valid, errors := v.ValidateQueryParams(request)

0 commit comments

Comments
 (0)