diff options
author | Wolfy-J <[email protected]> | 2018-09-07 23:26:26 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-09-07 23:26:26 +0300 |
commit | cac8bf48bab69ff3468cf7d30ac1c18904885a47 (patch) | |
tree | 5ffec205a9b51a933339d535de198a267be0275a /service/env | |
parent | ea97c188a4a74c00b585cb50fa1ed4db7d190e09 (diff) |
added ability to alter env values
Diffstat (limited to 'service/env')
-rw-r--r-- | service/env/provider.go | 7 | ||||
-rw-r--r-- | service/env/service.go | 7 | ||||
-rw-r--r-- | service/env/service_test.go | 18 |
3 files changed, 29 insertions, 3 deletions
diff --git a/service/env/provider.go b/service/env/provider.go index 2918f18c..d095009c 100644 --- a/service/env/provider.go +++ b/service/env/provider.go @@ -2,7 +2,10 @@ package env // Provider aggregates list of environment variables. This interface can be used in custom implementation to drive // values from external sources. -type Provider interface { +type Environment interface { // GetEnv must return list of env variables. GetEnv() (map[string]string, error) -} + + // SetEnv sets or creates environment value. + SetEnv(key, value string) +}
\ No newline at end of file diff --git a/service/env/service.go b/service/env/service.go index 0822d55a..b32a2f2b 100644 --- a/service/env/service.go +++ b/service/env/service.go @@ -15,7 +15,7 @@ func NewService(defaults map[string]string) *Service { if s.values == nil { s.values = make(map[string]string) } - + return s } @@ -33,3 +33,8 @@ func (s *Service) Init(cfg *Config) (bool, error) { func (s *Service) GetEnv() (map[string]string, error) { return s.values, nil } + +// SetEnv sets or creates environment value. +func (s *Service) SetEnv(key, value string) { + s.values[key] = value +} diff --git a/service/env/service_test.go b/service/env/service_test.go index 69a2a375..10159857 100644 --- a/service/env/service_test.go +++ b/service/env/service_test.go @@ -22,3 +22,21 @@ func Test_Extend(t *testing.T) { assert.Equal(t, "version", values["rr"]) assert.Equal(t, "value", values["key"]) } + + +func Test_Set(t *testing.T) { + s := NewService(map[string]string{"rr": "version"}) + + s.Init(&Config{Values: map[string]string{"key": "value"}}) + assert.Len(t, s.values, 2) + + s.SetEnv("key","value-new") + s.SetEnv("other","new") + + values, err := s.GetEnv() + assert.NoError(t, err) + assert.Len(t, values, 3) + assert.Equal(t, "version", values["rr"]) + assert.Equal(t, "value-new", values["key"]) + assert.Equal(t, "new", values["other"]) +}
\ No newline at end of file |