Skip to content

Commit

Permalink
Another bump in coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
daveshanley committed Oct 2, 2024
1 parent b1f5a94 commit 0a73ef5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
38 changes: 38 additions & 0 deletions errors/error_utilities_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023-2024 Princess Beef Heavy Industries, LLC / Dave Shanley
// https://pb33f.io

package errors

import (
"github.com/stretchr/testify/require"
"net/http"
"testing"
)

// Helper function to create a mock ValidationError
func createMockValidationError() *ValidationError {
return &ValidationError{
Message: "Test validation error",
}
}

func TestPopulateValidationErrors(t *testing.T) {
// Create a mock request
req, _ := http.NewRequest(http.MethodGet, "/test/path", nil)

// Create mock validation errors
validationErrors := []*ValidationError{
createMockValidationError(),
createMockValidationError(),
}

// Call the function
PopulateValidationErrors(validationErrors, req, "/spec/path")

// Validate the results
for _, validationError := range validationErrors {
require.Equal(t, "/spec/path", validationError.SpecPath)
require.Equal(t, http.MethodGet, validationError.RequestMethod)
require.Equal(t, "/test/path", validationError.RequestPath)
}
}
30 changes: 28 additions & 2 deletions errors/parameter_errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,30 @@ func TestInvalidCookieParamNumber(t *testing.T) {
require.Contains(t, err.HowToFix, "milky")
}

func TestIncorrectHeaderParamBool(t *testing.T) {

enum := `name: blip`
var n yaml.Node
_ = yaml.Unmarshal([]byte(enum), &n)

schemaProxy := &lowbase.SchemaProxy{}
schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)

highSchema := base.NewSchema(schemaProxy.Schema())
param := createMockParameter()
param.Name = "cookies"

err := IncorrectHeaderParamBool(param, "milky", highSchema)

// Validate the error
require.NotNil(t, err)
require.Equal(t, helpers.ParameterValidation, err.ValidationType)
require.Equal(t, helpers.ParameterValidationHeader, err.ValidationSubType)
require.Contains(t, err.Message, "Header parameter 'cookies' is not a valid boolean")
require.Contains(t, err.Reason, "The header parameter 'cookies' is defined as being a boolean")
require.Contains(t, err.HowToFix, "milky")
}

func TestIncorrectCookieParamBool(t *testing.T) {

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

func TestIncorrectCookieParamEnum(t *testing.T) {

enum := `items:
enum := `enum: [fish, crab, lobster]
items:
enum: [fish, crab, lobster]`
var n yaml.Node
_ = yaml.Unmarshal([]byte(enum), &n)
Expand Down Expand Up @@ -830,7 +855,8 @@ func TestIncorrectPathParamBool(t *testing.T) {
}

func TestIncorrectPathParamEnum(t *testing.T) {
items := `items:
items := `enum: [fish, crab, lobster]
items:
enum: [fish, crab, lobster]`

var n yaml.Node
Expand Down

0 comments on commit 0a73ef5

Please sign in to comment.