Skip to content

Commit

Permalink
feat(veinmind-common): provide new func for conf service
Browse files Browse the repository at this point in the history
  • Loading branch information
d1nfinite committed Jun 13, 2022
1 parent 188a074 commit 8a299fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 15 additions & 2 deletions veinmind-common/go/service/conf/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ import (
"testing"
)

func TestDefaultClient(t *testing.T) {
func TestDefaultClient(t *testing.T) {
c := DefaultConfClient()
_, err := c.Pull(Sensitive)
_, err := c.Pull(Sensitive)
assert.Error(t, err)
}

func TestNewConfService(t *testing.T) {
s, err := NewConfService()
if err != nil {
t.Error(err)
}

s.Store(Sensitive, []byte{0x01})
b, err := s.Pull(Sensitive)
if err != nil {
t.Error(err)
}

assert.Equal(t, b, []byte{0x01})
}
6 changes: 6 additions & 0 deletions veinmind-common/go/service/conf/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ type confClient struct {
Pull func(ns PluginConfNS) ([]byte, error)
}

func NewConfService() (*ConfService, error) {
c := new(ConfService)
c.store = make(map[PluginConfNS][]byte)
return c, nil
}

func (c *ConfService) Pull(ns PluginConfNS) ([]byte, error) {
if b, ok := c.store[ns]; ok {
return b, nil
Expand Down

0 comments on commit 8a299fa

Please sign in to comment.