summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-07-26 17:05:54 +0300
committerWolfy-J <[email protected]>2018-07-26 17:05:54 +0300
commit8226b1f064ba1dca8f817bb882e0e570fc057e43 (patch)
tree606261f4b57d3acc5c977f57253c848782f40952 /service
parent234995f297c4067f4dfdba305f3b16a90143cf12 (diff)
default service value as version
Diffstat (limited to 'service')
-rw-r--r--service/env/config.go3
-rw-r--r--service/env/config_test.go29
-rw-r--r--service/env/service.go13
3 files changed, 42 insertions, 3 deletions
diff --git a/service/env/config.go b/service/env/config.go
index 06342f98..1b743e84 100644
--- a/service/env/config.go
+++ b/service/env/config.go
@@ -12,6 +12,5 @@ type Config struct {
// Hydrate must populate Config values using given Config source. Must return error if Config is not valid.
func (c *Config) Hydrate(cfg service.Config) error {
- c.Values = map[string]string{"RR": "YES"}
return cfg.Unmarshal(&c.Values)
-}
+} \ No newline at end of file
diff --git a/service/env/config_test.go b/service/env/config_test.go
new file mode 100644
index 00000000..3c943963
--- /dev/null
+++ b/service/env/config_test.go
@@ -0,0 +1,29 @@
+package env
+
+import (
+ "github.com/spiral/roadrunner/service"
+ "encoding/json"
+ "testing"
+ "github.com/stretchr/testify/assert"
+)
+
+type mockCfg struct{ cfg string }
+
+func (cfg *mockCfg) Get(name string) service.Config { return nil }
+func (cfg *mockCfg) Unmarshal(out interface{}) error { return json.Unmarshal([]byte(cfg.cfg), out) }
+
+func Test_Config_Hydrate(t *testing.T) {
+ cfg := &mockCfg{`{"key":"value"}`}
+ c := &Config{}
+
+ assert.NoError(t, c.Hydrate(cfg))
+ assert.Len(t, c.Values, 1)
+}
+
+func Test_Config_Hydrate_Empty(t *testing.T) {
+ cfg := &mockCfg{`{}`}
+ c := &Config{}
+
+ assert.NoError(t, c.Hydrate(cfg))
+ assert.Len(t, c.Values, 0)
+} \ No newline at end of file
diff --git a/service/env/service.go b/service/env/service.go
index a90b0c48..b0721971 100644
--- a/service/env/service.go
+++ b/service/env/service.go
@@ -5,13 +5,24 @@ const ID = "env"
// Service provides ability to map _ENV values from config file.
type Service struct {
- cfg *Config
+ // Default is default set of values.
+ Default map[string]string
+ cfg *Config
+}
+
+// NewService creates new env service instance for given rr version.
+func NewService(version string) *Service {
+ return &Service{Default: 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
+ }
+
return true, nil
}