summaryrefslogtreecommitdiff
path: root/service/env
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-07-26 17:09:53 +0300
committerWolfy-J <[email protected]>2018-07-26 17:09:53 +0300
commit2f73d679b884616c49f4eba3342b350c001d949f (patch)
treee93f4f9505bcb0d597f8a258b046c735e4ff3245 /service/env
parent8226b1f064ba1dca8f817bb882e0e570fc057e43 (diff)
more tests
Diffstat (limited to 'service/env')
-rw-r--r--service/env/config.go2
-rw-r--r--service/env/service.go14
-rw-r--r--service/env/service_test.go24
3 files changed, 31 insertions, 9 deletions
diff --git a/service/env/config.go b/service/env/config.go
index 1b743e84..ad7eddf5 100644
--- a/service/env/config.go
+++ b/service/env/config.go
@@ -6,7 +6,7 @@ import (
// Config defines set of env values for RR workers.
type Config struct {
- // Values to set as worker _ENV.
+ // values to set as worker _ENV.
Values map[string]string
}
diff --git a/service/env/service.go b/service/env/service.go
index b0721971..9fb110c3 100644
--- a/service/env/service.go
+++ b/service/env/service.go
@@ -5,22 +5,20 @@ const ID = "env"
// Service provides ability to map _ENV values from config file.
type Service struct {
- // Default is default set of values.
- Default map[string]string
- cfg *Config
+ // values is default set of values.
+ values map[string]string
}
// NewService creates new env service instance for given rr version.
func NewService(version string) *Service {
- return &Service{Default: map[string]string{"rr": version}}
+ return &Service{values: map[string]string{"rr": version}}
}
// Init must return configure svc and return true if svc hasStatus enabled. Must return error in case of
// misconfiguration. Services must not be used without proper configuration pushed first.
func (s *Service) Init(cfg *Config) (bool, error) {
- s.cfg = cfg
- for k, v := range s.Default {
- s.cfg.Values[k] = v
+ for k, v := range cfg.Values {
+ s.values[k] = v
}
return true, nil
@@ -28,5 +26,5 @@ func (s *Service) Init(cfg *Config) (bool, error) {
// GetEnv must return list of env variables.
func (s *Service) GetEnv() (map[string]string, error) {
- return s.cfg.Values, nil
+ return s.values, nil
}
diff --git a/service/env/service_test.go b/service/env/service_test.go
new file mode 100644
index 00000000..4d823468
--- /dev/null
+++ b/service/env/service_test.go
@@ -0,0 +1,24 @@
+package env
+
+import (
+ "testing"
+ "github.com/stretchr/testify/assert"
+)
+
+func Test_NewService(t *testing.T) {
+ s := NewService("version")
+ assert.Len(t, s.values, 1)
+}
+
+func Test_Extend(t *testing.T) {
+ s := NewService("version")
+
+ s.Init(&Config{Values: map[string]string{"key": "value"}})
+ assert.Len(t, s.values, 2)
+
+ values, err := s.GetEnv()
+ assert.NoError(t, err)
+ assert.Len(t, values, 2)
+ assert.Equal(t, "version", values["rr"])
+ assert.Equal(t, "value", values["key"])
+}