Skip to content

Commit

Permalink
[Dembo] Change config type for notification plugin binary
Browse files Browse the repository at this point in the history
  • Loading branch information
walbertus committed Sep 19, 2019
1 parent 74a39d6 commit 1f33a58
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
8 changes: 6 additions & 2 deletions internal/app/service/infra/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/spf13/viper"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -82,7 +83,7 @@ type ProctorConfig struct {
DocsPath string
AuthPluginBinary string
AuthEnabled bool
NotificationPluginBinary string
NotificationPluginBinary []string
NotificationPluginExported string
}

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

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

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 @@ -217,9 +217,10 @@ func TestAuthEnabled(t *testing.T) {
}

func TestNotificationPluginBinary(t *testing.T) {
_ = os.Setenv("PROCTOR_NOTIFICATION_PLUGIN_BINARY", "path-notification")
_ = os.Setenv("PROCTOR_NOTIFICATION_PLUGIN_BINARY", "path-notification,second-path")

assert.Equal(t, "path-notification", Load().NotificationPluginBinary)
expected := []string{"path-notification", "second-path"}
assert.Equal(t, expected, Load().NotificationPluginBinary)
}

func TestNotificationPluginExported(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestGoPlugin_LoadNotificationSuccessfully(t *testing.T) {
ctx := newContext()
ctx.setUp(t)

pluginsBinary := strings.Split(config.Config().NotificationPluginBinary, ",")
pluginsBinary := config.Config().NotificationPluginBinary
pluginsExported := strings.Split(config.Config().NotificationPluginExported, ",")
for idx, pluginBinary := range pluginsBinary {
pluginExported := pluginsExported[idx]
Expand Down
6 changes: 3 additions & 3 deletions internal/app/service/notification/service/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type NotificationService interface {
type notificationService struct {
observers []notification.Observer
goPlugin plugin.GoPlugin
pluginsBinary string
pluginsBinary []string
pluginsExportedName string
once sync.Once
}
Expand All @@ -32,7 +32,7 @@ func (s *notificationService) Notify(evt event.Event) {
func (s *notificationService) initializePlugin() {
s.once.Do(func() {
s.observers = []notification.Observer{}
pluginsBinary := strings.Split(s.pluginsBinary, ",")
pluginsBinary := s.pluginsBinary
pluginsExported := strings.Split(s.pluginsExportedName, ",")

for idx, pluginBinary := range pluginsBinary {
Expand All @@ -52,7 +52,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 1f33a58

Please sign in to comment.