From 2f73d679b884616c49f4eba3342b350c001d949f Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Thu, 26 Jul 2018 17:09:53 +0300 Subject: more tests --- service/env/config.go | 2 +- service/env/service.go | 14 ++++++-------- service/env/service_test.go | 24 ++++++++++++++++++++++++ service/http/request.go | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 service/env/service_test.go (limited to 'service') 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"]) +} diff --git a/service/http/request.go b/service/http/request.go index 6d5cc126..531a1efd 100644 --- a/service/http/request.go +++ b/service/http/request.go @@ -126,7 +126,7 @@ func (r *Request) Close() { r.Uploads.Clear() } -// Payload request marshaled RoadRunner payload based on PSR7 data. Default encode method is JSON. Make sure to open +// Payload request marshaled RoadRunner payload based on PSR7 data. values encode method is JSON. Make sure to open // files prior to calling this method. func (r *Request) Payload() (p *roadrunner.Payload, err error) { p = &roadrunner.Payload{} -- cgit v1.2.3