Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsirbe authored and daveshanley committed Apr 28, 2024
1 parent fcb62d5 commit 5b5766b
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions requests/validate_request_test.go
Expand Up @@ -18,13 +18,8 @@ func TestValidateRequestSchema(t *testing.T) {
assertValidRequestSchema assert.BoolAssertionFunc
expectedErrorsCount int
}{
"FailRequestBodyValidation": {
// KeywordLocation: /allOf/1/$ref/properties/properties/additionalProperties/$dynamicRef/allOf/3/$ref/properties/exclusiveMinimum/type
// Message: expected number, but got boolean
request: &http.Request{
Method: http.MethodPost,
Body: io.NopCloser(strings.NewReader(`{"exclusiveNumber": 13}`)),
},
"FailOnBooleanExclusiveMinimum": {
request: postRequestWithBody(`{"exclusiveNumber": 13}`),
schema: &base.Schema{
Type: []string{"object"},
},
Expand All @@ -39,6 +34,37 @@ properties:
assertValidRequestSchema: assert.False,
expectedErrorsCount: 1,
},
"PassWithCorrectExclusiveMinimum": {
request: postRequestWithBody(`{"exclusiveNumber": 15}`),
schema: &base.Schema{
Type: []string{"object"},
},
renderedSchema: []byte(`type: object
properties:
exclusiveNumber:
type: number
description: This number is properly constrained by a numeric exclusive minimum.
exclusiveMinimum: 12
minimum: 12`),
jsonSchema: []byte(`{"properties":{"exclusiveNumber":{"type":"number","description":"This number is properly constrained by a numeric exclusive minimum.","exclusiveMinimum":12,"minimum":12}},"type":"object"}`),
assertValidRequestSchema: assert.True,
expectedErrorsCount: 0,
},
"PassWithValidStringType": {
request: postRequestWithBody(`{"greeting": "Hello, world!"}`),
schema: &base.Schema{
Type: []string{"object"},
},
renderedSchema: []byte(`type: object
properties:
greeting:
type: string
description: A simple greeting
example: "Hello, world!"`),
jsonSchema: []byte(`{"properties":{"greeting":{"type":"string","description":"A simple greeting","example":"Hello, world!"}},"type":"object"}`),
assertValidRequestSchema: assert.True,
expectedErrorsCount: 0,
},
} {
tc := tc
t.Run(name, func(t *testing.T) {
Expand All @@ -51,3 +77,10 @@ properties:
})
}
}

func postRequestWithBody(payload string) *http.Request {
return &http.Request{
Method: http.MethodPost,
Body: io.NopCloser(strings.NewReader(payload)),
}
}

0 comments on commit 5b5766b

Please sign in to comment.