Debian Codegraph @

errors/error_utilities_test.go

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