Skip to content

Commit 0a73ef5

Browse files
committed
Another bump in coverage
1 parent b1f5a94 commit 0a73ef5

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

errors/error_utilities_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2023-2024 Princess Beef Heavy Industries, LLC / Dave Shanley
2+
// https://pb33f.io
3+
4+
package errors
5+
6+
import (
7+
"github.com/stretchr/testify/require"
8+
"net/http"
9+
"testing"
10+
)
11+
12+
// Helper function to create a mock ValidationError
13+
func createMockValidationError() *ValidationError {
14+
return &ValidationError{
15+
Message: "Test validation error",
16+
}
17+
}
18+
19+
func TestPopulateValidationErrors(t *testing.T) {
20+
// Create a mock request
21+
req, _ := http.NewRequest(http.MethodGet, "/test/path", nil)
22+
23+
// Create mock validation errors
24+
validationErrors := []*ValidationError{
25+
createMockValidationError(),
26+
createMockValidationError(),
27+
}
28+
29+
// Call the function
30+
PopulateValidationErrors(validationErrors, req, "/spec/path")
31+
32+
// Validate the results
33+
for _, validationError := range validationErrors {
34+
require.Equal(t, "/spec/path", validationError.SpecPath)
35+
require.Equal(t, http.MethodGet, validationError.RequestMethod)
36+
require.Equal(t, "/test/path", validationError.RequestPath)
37+
}
38+
}

errors/parameter_errors_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,30 @@ func TestInvalidCookieParamNumber(t *testing.T) {
695695
require.Contains(t, err.HowToFix, "milky")
696696
}
697697

698+
func TestIncorrectHeaderParamBool(t *testing.T) {
699+
700+
enum := `name: blip`
701+
var n yaml.Node
702+
_ = yaml.Unmarshal([]byte(enum), &n)
703+
704+
schemaProxy := &lowbase.SchemaProxy{}
705+
schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)
706+
707+
highSchema := base.NewSchema(schemaProxy.Schema())
708+
param := createMockParameter()
709+
param.Name = "cookies"
710+
711+
err := IncorrectHeaderParamBool(param, "milky", highSchema)
712+
713+
// Validate the error
714+
require.NotNil(t, err)
715+
require.Equal(t, helpers.ParameterValidation, err.ValidationType)
716+
require.Equal(t, helpers.ParameterValidationHeader, err.ValidationSubType)
717+
require.Contains(t, err.Message, "Header parameter 'cookies' is not a valid boolean")
718+
require.Contains(t, err.Reason, "The header parameter 'cookies' is defined as being a boolean")
719+
require.Contains(t, err.HowToFix, "milky")
720+
}
721+
698722
func TestIncorrectCookieParamBool(t *testing.T) {
699723

700724
enum := `name: blip`
@@ -721,7 +745,8 @@ func TestIncorrectCookieParamBool(t *testing.T) {
721745

722746
func TestIncorrectCookieParamEnum(t *testing.T) {
723747

724-
enum := `items:
748+
enum := `enum: [fish, crab, lobster]
749+
items:
725750
enum: [fish, crab, lobster]`
726751
var n yaml.Node
727752
_ = yaml.Unmarshal([]byte(enum), &n)
@@ -830,7 +855,8 @@ func TestIncorrectPathParamBool(t *testing.T) {
830855
}
831856

832857
func TestIncorrectPathParamEnum(t *testing.T) {
833-
items := `items:
858+
items := `enum: [fish, crab, lobster]
859+
items:
834860
enum: [fish, crab, lobster]`
835861

836862
var n yaml.Node

0 commit comments

Comments
 (0)