updated the interface to return a Error struct and modified the function and tests accordingly
This commit is contained in:
@@ -11,11 +11,11 @@ import (
|
||||
type ValidatorProvider struct{}
|
||||
|
||||
// New initializes a new Verifier instance.
|
||||
func (vp ValidatorProvider) New(ctx context.Context, config map[string]string) (map[string]definition.Validator, error) {
|
||||
func (vp ValidatorProvider) New(ctx context.Context, config map[string]string) (map[string]definition.Validator, definition.Error) {
|
||||
// Create a new Validator instance with the provided configuration
|
||||
validators, err := validator.New(ctx, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err != (definition.Error{}) {
|
||||
return nil, definition.Error{Path: "", Message: err.Message}
|
||||
}
|
||||
|
||||
// Convert the map to the expected type
|
||||
@@ -24,8 +24,8 @@ func (vp ValidatorProvider) New(ctx context.Context, config map[string]string) (
|
||||
result[key] = val
|
||||
}
|
||||
|
||||
return result, nil
|
||||
return result, definition.Error{}
|
||||
}
|
||||
|
||||
// Provider is the exported symbol that the plugin manager will look for.
|
||||
var Provider definition.ValidatorProvider = ValidatorProvider{}
|
||||
var Provider definition.ValidatorProvider = &ValidatorProvider{}
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
// MockValidator is a mock implementation of the Validator interface for testing.
|
||||
type MockValidator struct{}
|
||||
|
||||
func (m *MockValidator) Validate(ctx context.Context, u url.URL, data []byte) (bool, error) {
|
||||
return true, nil
|
||||
func (m *MockValidator) Validate(ctx context.Context, u *url.URL, data []byte) (bool, definition.Error) {
|
||||
return true, (definition.Error{})
|
||||
}
|
||||
|
||||
// Mock New function for testing
|
||||
@@ -70,7 +70,7 @@ func TestValidatorProvider_New(t *testing.T) {
|
||||
|
||||
// Check for expected error
|
||||
if tt.expectedError != "" {
|
||||
if err == nil || err.Error() != tt.expectedError {
|
||||
if err == (definition.Error{}) || err.Message != tt.expectedError {
|
||||
t.Errorf("expected error %q, got %v", tt.expectedError, err)
|
||||
}
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user