small fixes
This commit is contained in:
@@ -17,10 +17,10 @@ func (vp schemaValidatorProvider) New(ctx context.Context, config map[string]str
|
||||
return nil, nil, errors.New("context cannot be nil")
|
||||
}
|
||||
|
||||
// Extract schema_dir from the config map
|
||||
schemaDir, ok := config["schema_dir"]
|
||||
// Extract schemaDir from the config map
|
||||
schemaDir, ok := config["schemaDir"]
|
||||
if !ok || schemaDir == "" {
|
||||
return nil, nil, errors.New("config must contain 'schema_dir'")
|
||||
return nil, nil, errors.New("config must contain 'schemaDir'")
|
||||
}
|
||||
|
||||
// Create a new schemaValidator instance with the provided configuration
|
||||
|
||||
@@ -63,7 +63,7 @@ func TestValidatorProviderSuccess(t *testing.T) {
|
||||
{
|
||||
name: "Valid schema directory",
|
||||
ctx: context.Background(), // Valid context
|
||||
config: map[string]string{"schema_dir": schemaDir},
|
||||
config: map[string]string{"schemaDir": schemaDir},
|
||||
expectedError: "",
|
||||
},
|
||||
}
|
||||
@@ -114,24 +114,24 @@ func TestValidatorProviderFailure(t *testing.T) {
|
||||
name: "Config is empty",
|
||||
ctx: context.Background(),
|
||||
config: map[string]string{},
|
||||
expectedError: "config must contain 'schema_dir'",
|
||||
expectedError: "config must contain 'schemaDir'",
|
||||
},
|
||||
{
|
||||
name: "schema_dir is empty",
|
||||
name: "schemaDir is empty",
|
||||
ctx: context.Background(),
|
||||
config: map[string]string{"schema_dir": ""},
|
||||
expectedError: "config must contain 'schema_dir'",
|
||||
config: map[string]string{"schemaDir": ""},
|
||||
expectedError: "config must contain 'schemaDir'",
|
||||
},
|
||||
{
|
||||
name: "Invalid schema directory",
|
||||
ctx: context.Background(), // Valid context
|
||||
config: map[string]string{"schema_dir": "/invalid/dir"},
|
||||
config: map[string]string{"schemaDir": "/invalid/dir"},
|
||||
expectedError: "failed to initialise schemaValidator: schema directory does not exist: /invalid/dir",
|
||||
},
|
||||
{
|
||||
name: "Nil context",
|
||||
ctx: nil, // Nil context
|
||||
config: map[string]string{"schema_dir": schemaDir},
|
||||
config: map[string]string{"schemaDir": schemaDir},
|
||||
expectedError: "context cannot be nil",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func New(ctx context.Context, config *Config) (*SchemaValidator, func() error, e
|
||||
if err := v.initialise(); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to initialise schemaValidator: %v", err)
|
||||
}
|
||||
return v, v.Close, nil
|
||||
return v, nil, nil
|
||||
}
|
||||
|
||||
// Validate validates the given data against the schema.
|
||||
@@ -195,8 +195,3 @@ func (v *SchemaValidator) initialise() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close releases resources (mock implementation returning nil).
|
||||
func (v *SchemaValidator) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ func TestValidator_Initialise(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidator_New_Success(t *testing.T) {
|
||||
func TestValidatorNew_Success(t *testing.T) {
|
||||
schemaDir := setupTestSchema(t)
|
||||
defer os.RemoveAll(schemaDir)
|
||||
|
||||
@@ -300,7 +300,7 @@ func TestValidator_New_Success(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidator_New_Failure(t *testing.T) {
|
||||
func TestValidatorNewFailure(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
config *Config
|
||||
@@ -315,22 +315,6 @@ func TestValidator_New_Failure(t *testing.T) {
|
||||
},
|
||||
wantErr: "config cannot be nil",
|
||||
},
|
||||
// {
|
||||
// name: "Config is empty",
|
||||
// config: &Config{},
|
||||
// setupFunc: func(schemaDir string) error {
|
||||
// return nil
|
||||
// },
|
||||
// wantErr: "config must contain 'schema_dir'",
|
||||
// },
|
||||
// {
|
||||
// name: "schema_dir is empty",
|
||||
// config: &Config{SchemaDir: ""},
|
||||
// setupFunc: func(schemaDir string) error {
|
||||
// return nil
|
||||
// },
|
||||
// wantErr: "config must contain 'schema_dir'",
|
||||
// },
|
||||
{
|
||||
name: "Failed to initialise validators",
|
||||
config: &Config{
|
||||
|
||||
Reference in New Issue
Block a user