-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
113fcc1
commit fbf9606
Showing
2 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters