Changes to Response Error struct

This commit is contained in:
tanyamadaan
2025-03-19 13:54:23 +05:30
22 changed files with 1532 additions and 84 deletions

View File

@@ -5,10 +5,10 @@ import (
"errors"
definition "github.com/beckn/beckn-onix/pkg/plugin/definition"
validator "github.com/beckn/beckn-onix/pkg/plugin/implementation/schemaValidator"
schemaValidator "github.com/beckn/beckn-onix/pkg/plugin/implementation/schemaValidator"
)
// ValidatorProvider provides instance of Validator.
// schemaValidatorProvider provides instances of schemaValidator.
type schemaValidatorProvider struct{}
// New initializes a new Verifier instance.
@@ -23,11 +23,11 @@ func (vp schemaValidatorProvider) New(ctx context.Context, config map[string]str
return nil, nil, errors.New("config must contain 'schema_dir'")
}
// Create a new Validator instance with the provided configuration
return validator.New(ctx, &validator.Config{
SchemaDir: schemaDir, // Pass the schemaDir to the validator.Config
// Create a new schemaValidator instance with the provided configuration
return schemaValidator.New(ctx, &schemaValidator.Config{
SchemaDir: schemaDir,
})
}
// Provider is the exported symbol that the plugin manager will look for.
var Provider definition.SchemaValidatorProvider = &schemaValidatorProvider{}
var Provider definition.SchemaValidatorProvider = schemaValidatorProvider{}

View File

@@ -72,7 +72,7 @@ func TestValidatorProviderSuccess(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
vp := schemaValidatorProvider{}
validator, close, err := vp.New(tt.ctx, tt.config)
schemaValidator, close, err := vp.New(tt.ctx, tt.config)
// Ensure no error occurred
if err != nil {
@@ -80,9 +80,9 @@ func TestValidatorProviderSuccess(t *testing.T) {
return
}
// Ensure the validator is not nil
if validator == nil {
t.Error("expected a non-nil validator, got nil")
// Ensure the schemaValidator is not nil
if schemaValidator == nil {
t.Error("expected a non-nil schemaValidator, got nil")
}
// Ensure the close function is not nil
@@ -110,11 +110,23 @@ func TestValidatorProviderFailure(t *testing.T) {
config map[string]string
expectedError string
}{
{
name: "Config is empty",
ctx: context.Background(),
config: map[string]string{},
expectedError: "config must contain 'schema_dir'",
},
{
name: "schema_dir is empty",
ctx: context.Background(),
config: map[string]string{"schema_dir": ""},
expectedError: "config must contain 'schema_dir'",
},
{
name: "Invalid schema directory",
ctx: context.Background(), // Valid context
config: map[string]string{"schema_dir": "/invalid/dir"},
expectedError: "failed to initialise validator: schema directory does not exist: /invalid/dir",
expectedError: "failed to initialise schemaValidator: schema directory does not exist: /invalid/dir",
},
{
name: "Nil context",