Skip to content

Commit

Permalink
[Dembo] Change config type for notification plugin exported name
Browse files Browse the repository at this point in the history
  • Loading branch information
walbertus committed Sep 19, 2019
1 parent 1f33a58 commit 456f621
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
7 changes: 4 additions & 3 deletions internal/app/service/infra/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type ProctorConfig struct {
AuthPluginBinary string
AuthEnabled bool
NotificationPluginBinary []string
NotificationPluginExported string
NotificationPluginExported []string
}

func Load() ProctorConfig {
Expand Down Expand Up @@ -129,13 +129,14 @@ func Load() ProctorConfig {
AuthPluginBinary: fang.GetString("AUTH_PLUGIN_BINARY"),
AuthPluginExported: GetStringDefault(fang, "AUTH_PLUGIN_EXPORTED", "Auth"),
AuthEnabled: GetBoolDefault(fang, "AUTH_ENABLED", false),
NotificationPluginExported: fang.GetString("NOTIFICATION_PLUGIN_EXPORTED"),
}

notificationPluginsBinary := strings.Split(fang.GetString("NOTIFICATION_PLUGIN_BINARY"), ",")
proctorConfig.NotificationPluginBinary = []string{}
proctorConfig.NotificationPluginBinary = append(proctorConfig.NotificationPluginBinary, notificationPluginsBinary...)

notificationPluginsExported := strings.Split(fang.GetString("NOTIFICATION_PLUGIN_EXPORTED"), ",")
proctorConfig.NotificationPluginExported = append([]string{}, notificationPluginsExported...)

return proctorConfig
}

Expand Down
5 changes: 3 additions & 2 deletions internal/app/service/infra/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ func TestNotificationPluginBinary(t *testing.T) {
}

func TestNotificationPluginExported(t *testing.T) {
_ = os.Setenv("PROCTOR_NOTIFICATION_PLUGIN_EXPORTED", "plugin-notification")
_ = os.Setenv("PROCTOR_NOTIFICATION_PLUGIN_EXPORTED", "plugin-notification,second-plugin")

assert.Equal(t, "plugin-notification", Load().NotificationPluginExported)
expected := []string{"plugin-notification", "second-plugin"}
assert.Equal(t, expected, Load().NotificationPluginExported)
}
3 changes: 1 addition & 2 deletions internal/app/service/infra/plugin/plugin_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package plugin
import (
"fmt"
"os"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -77,7 +76,7 @@ func TestGoPlugin_LoadNotificationSuccessfully(t *testing.T) {
ctx.setUp(t)

pluginsBinary := config.Config().NotificationPluginBinary
pluginsExported := strings.Split(config.Config().NotificationPluginExported, ",")
pluginsExported := config.Config().NotificationPluginExported
for idx, pluginBinary := range pluginsBinary {
pluginExported := pluginsExported[idx]
raw, err := ctx.instance().goPlugin.Load(pluginBinary, pluginExported)
Expand Down
12 changes: 4 additions & 8 deletions internal/app/service/notification/service/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"proctor/internal/app/service/infra/plugin"
"proctor/pkg/notification"
"proctor/pkg/notification/event"
"strings"
"sync"
)

Expand All @@ -17,7 +16,7 @@ type notificationService struct {
observers []notification.Observer
goPlugin plugin.GoPlugin
pluginsBinary []string
pluginsExportedName string
pluginsExportedName []string
once sync.Once
}

Expand All @@ -32,11 +31,8 @@ func (s *notificationService) Notify(evt event.Event) {
func (s *notificationService) initializePlugin() {
s.once.Do(func() {
s.observers = []notification.Observer{}
pluginsBinary := s.pluginsBinary
pluginsExported := strings.Split(s.pluginsExportedName, ",")

for idx, pluginBinary := range pluginsBinary {
raw, err := s.goPlugin.Load(pluginBinary, pluginsExported[idx])
for idx, pluginBinary := range s.pluginsBinary {
raw, err := s.goPlugin.Load(pluginBinary, s.pluginsExportedName[idx])
logger.LogErrors(err, "Load GoPlugin binary")
if err != nil {
return
Expand All @@ -52,7 +48,7 @@ func (s *notificationService) initializePlugin() {
})
}

func NewNotificationService(pluginsBinary []string, pluginsExportedName string, goPlugin plugin.GoPlugin) NotificationService {
func NewNotificationService(pluginsBinary []string, pluginsExportedName []string, goPlugin plugin.GoPlugin) NotificationService {
return &notificationService{
goPlugin: goPlugin,
pluginsBinary: pluginsBinary,
Expand Down

0 comments on commit 456f621

Please sign in to comment.