Skip to content

Commit 2b72777

Browse files
committed
bumped coverage
1 parent ba01d08 commit 2b72777

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

errors/parameter_errors_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,3 +976,81 @@ func TestPathParameterMissing(t *testing.T) {
976976
require.Contains(t, err.Reason, "The path parameter 'testQueryParam' is defined as being required")
977977
require.Contains(t, err.HowToFix, "Ensure the value has been set")
978978
}
979+
980+
func TestPathParameterMaxItems(t *testing.T) {
981+
items := `maxItems: 5
982+
items:
983+
type: string`
984+
var n yaml.Node
985+
_ = yaml.Unmarshal([]byte(items), &n)
986+
987+
schemaProxy := &lowbase.SchemaProxy{}
988+
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil))
989+
990+
highSchema := base.NewSchema(schemaProxy.Schema())
991+
param := createMockParameter()
992+
param.Schema = base.CreateSchemaProxy(highSchema)
993+
param.GoLow().Schema.KeyNode = &yaml.Node{}
994+
995+
err := IncorrectParamArrayMaxNumItems(param, param.Schema.Schema(), 10, 25)
996+
997+
// Validate the error
998+
require.NotNil(t, err)
999+
require.Equal(t, helpers.ParameterValidation, err.ValidationType)
1000+
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType)
1001+
require.Contains(t, err.Message, "Query array parameter 'testQueryParam' has too many items")
1002+
require.Contains(t, err.Reason, "The query parameter (which is an array) 'testQueryParam' has a maximum item length of 10, however the request provided 25 items")
1003+
require.Contains(t, err.HowToFix, "Reduce the number of items in the array to 10 or less")
1004+
}
1005+
1006+
func TestPathParameterMinItems(t *testing.T) {
1007+
items := `minItems: 5
1008+
items:
1009+
type: string`
1010+
var n yaml.Node
1011+
_ = yaml.Unmarshal([]byte(items), &n)
1012+
1013+
schemaProxy := &lowbase.SchemaProxy{}
1014+
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil))
1015+
1016+
highSchema := base.NewSchema(schemaProxy.Schema())
1017+
param := createMockParameter()
1018+
param.Schema = base.CreateSchemaProxy(highSchema)
1019+
param.GoLow().Schema.KeyNode = &yaml.Node{}
1020+
1021+
err := IncorrectParamArrayMinNumItems(param, param.Schema.Schema(), 10, 5)
1022+
1023+
// Validate the error
1024+
require.NotNil(t, err)
1025+
require.Equal(t, helpers.ParameterValidation, err.ValidationType)
1026+
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType)
1027+
require.Contains(t, err.Message, "Query array parameter 'testQueryParam' does not have enough items")
1028+
require.Contains(t, err.Reason, "The query parameter (which is an array) 'testQueryParam' has a minimum items length of 10, however the request provided 5 items")
1029+
require.Contains(t, err.HowToFix, "Increase the number of items in the array to 10 or more")
1030+
}
1031+
1032+
func TestPathParameterUniqueItems(t *testing.T) {
1033+
items := `uniqueItems: true
1034+
items:
1035+
type: string`
1036+
var n yaml.Node
1037+
_ = yaml.Unmarshal([]byte(items), &n)
1038+
1039+
schemaProxy := &lowbase.SchemaProxy{}
1040+
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil))
1041+
1042+
highSchema := base.NewSchema(schemaProxy.Schema())
1043+
param := createMockParameter()
1044+
param.Schema = base.CreateSchemaProxy(highSchema)
1045+
param.GoLow().Schema.KeyNode = &yaml.Node{}
1046+
1047+
err := IncorrectParamArrayUniqueItems(param, param.Schema.Schema(), "fish, cake")
1048+
1049+
// Validate the error
1050+
require.NotNil(t, err)
1051+
require.Equal(t, helpers.ParameterValidation, err.ValidationType)
1052+
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType)
1053+
require.Contains(t, err.Message, "Query array parameter 'testQueryParam' contains non-unique items")
1054+
require.Contains(t, err.Reason, "The query parameter (which is an array) 'testQueryParam' contains the following duplicates: 'fish, cake'")
1055+
require.Contains(t, err.HowToFix, "Ensure the array values are all unique")
1056+
}

0 commit comments

Comments
 (0)