feat: encryption plugin (#429)

* feat: Implement encryption plugin.

* fix: Removed interface test file

* fix: Test case changes

* fix: Test case for encryption

* fix: formatting changes

* fix: lint change

* fix: shared renamed to pkg

* fix: shared rename to pkg

* fix: resolved pr comments

* fix: indentation, formatting

* fix: removed config, ctx check, test enhancements

* fix: removed close function

* fix: remove config and enhance test cases

* fix: formatting changes, test case enhancement
This commit is contained in:
rupinder-syngh
2025-03-21 17:18:51 +05:30
committed by GitHub
parent e07a6cdad9
commit d6ba0edb27
8 changed files with 360 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
package main
import (
"context"
"github.com/beckn/beckn-onix/pkg/plugin/definition"
"github.com/beckn/beckn-onix/pkg/plugin/implementation/encrypter"
)
// EncrypterProvider implements the definition.EncrypterProvider interface.
type EncrypterProvider struct{}
func (ep EncrypterProvider) New(ctx context.Context, config map[string]string) (definition.Encrypter, func() error, error) {
return encrypter.New(ctx)
}
// Provider is the exported symbol that the plugin manager will look for.
var Provider definition.EncrypterProvider = EncrypterProvider{}

View File

@@ -0,0 +1,49 @@
package main
import (
"context"
"testing"
)
func TestEncrypterProviderSuccess(t *testing.T) {
tests := []struct {
name string
ctx context.Context
config map[string]string
}{
{
name: "Valid empty config",
ctx: context.Background(),
config: map[string]string{},
},
{
name: "Valid config with algorithm",
ctx: context.Background(),
config: map[string]string{
"algorithm": "AES",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Create provider and encrypter.
provider := EncrypterProvider{}
encrypter, cleanup, err := provider.New(tt.ctx, tt.config)
if err != nil {
t.Fatalf("EncrypterProvider.New() error = %v", err)
}
if encrypter == nil {
t.Fatal("EncrypterProvider.New() returned nil encrypter")
}
defer func() {
if cleanup != nil {
if err := cleanup(); err != nil {
t.Errorf("Cleanup() error = %v", err)
}
}
}()
})
}
}