diff options
author | Valery Piashchynski <[email protected]> | 2020-11-05 17:58:23 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2020-11-05 17:58:23 +0300 |
commit | 9fbe7726dd55cfedda724b7644e1b6bf7c1a6cb4 (patch) | |
tree | f2bf9b97d38103de51e2d140aa76666f9c6341c8 /plugins/config | |
parent | edc45b3e24afdb5e56e74ffbbbd50e0e3b04922b (diff) | |
parent | 73da7300fcc9b8b22faa1c91fc1faff22ab944ff (diff) |
Merge pull request #388 from spiral/enhancement/testsv2.0.0-alpha15
Tests for the new plugins
Diffstat (limited to 'plugins/config')
-rwxr-xr-x | plugins/config/configurer.go (renamed from plugins/config/provider.go) | 4 | ||||
-rwxr-xr-x | plugins/config/plugin.go (renamed from plugins/config/viper.go) | 12 | ||||
-rwxr-xr-x | plugins/config/tests/.rr.yaml | 10 | ||||
-rwxr-xr-x | plugins/config/tests/config_test.go | 4 | ||||
-rwxr-xr-x | plugins/config/tests/plugin1.go | 4 |
5 files changed, 12 insertions, 22 deletions
diff --git a/plugins/config/provider.go b/plugins/config/configurer.go index ac33b3de..00010eae 100755 --- a/plugins/config/provider.go +++ b/plugins/config/configurer.go @@ -1,9 +1,9 @@ package config -type Provider interface { +type Configurer interface { // UnmarshalKey reads configuration section into configuration object. // - // func (h *HttpService) Init(cp config.Provider) error { + // func (h *HttpService) Init(cp config.Configurer) error { // h.config := &HttpConfig{} // if err := configProvider.UnmarshalKey("http", h.config); err != nil { // return err diff --git a/plugins/config/viper.go b/plugins/config/plugin.go index 4e85af6b..2555d28a 100755 --- a/plugins/config/viper.go +++ b/plugins/config/plugin.go @@ -8,14 +8,14 @@ import ( "github.com/spf13/viper" ) -type ViperProvider struct { +type Viper struct { viper *viper.Viper Path string Prefix string } // Inits config provider. -func (v *ViperProvider) Init() error { +func (v *Viper) Init() error { v.viper = viper.New() // read in environment variables that match @@ -36,7 +36,7 @@ func (v *ViperProvider) Init() error { } // Overwrite overwrites existing config with provided values -func (v *ViperProvider) Overwrite(values map[string]string) error { +func (v *Viper) Overwrite(values map[string]string) error { if len(values) != 0 { for _, flag := range values { key, value, err := parseFlag(flag) @@ -51,7 +51,7 @@ func (v *ViperProvider) Overwrite(values map[string]string) error { } // UnmarshalKey reads configuration section into configuration object. -func (v *ViperProvider) UnmarshalKey(name string, out interface{}) error { +func (v *Viper) UnmarshalKey(name string, out interface{}) error { err := v.viper.UnmarshalKey(name, &out) if err != nil { return err @@ -60,12 +60,12 @@ func (v *ViperProvider) UnmarshalKey(name string, out interface{}) error { } // Get raw config in a form of config section. -func (v *ViperProvider) Get(name string) interface{} { +func (v *Viper) Get(name string) interface{} { return v.viper.Get(name) } // Has checks if config section exists. -func (v *ViperProvider) Has(name string) bool { +func (v *Viper) Has(name string) bool { return v.viper.IsSet(name) } diff --git a/plugins/config/tests/.rr.yaml b/plugins/config/tests/.rr.yaml index df9077d0..732a1366 100755 --- a/plugins/config/tests/.rr.yaml +++ b/plugins/config/tests/.rr.yaml @@ -1,21 +1,12 @@ reload: - # enable or disable file watcher enabled: true - # sync interval interval: 1s - # global patterns to sync patterns: [".php"] - # list of included for sync services services: http: - # recursive search for file patterns to add recursive: true - # ignored folders ignore: ["vendor"] - # service specific file pattens to sync patterns: [".php", ".go",".md",] - # directories to sync. If recursive is set to true, - # recursive sync will be applied only to the directories in `dirs` section dirs: ["."] jobs: recursive: false @@ -24,5 +15,4 @@ reload: rpc: recursive: true patterns: [".json"] - # to include all project directories from workdir, leave `dirs` empty or add a dot "." dirs: [""] diff --git a/plugins/config/tests/config_test.go b/plugins/config/tests/config_test.go index 14e60ac2..422e7eee 100755 --- a/plugins/config/tests/config_test.go +++ b/plugins/config/tests/config_test.go @@ -12,11 +12,11 @@ import ( ) func TestViperProvider_Init(t *testing.T) { - container, err := endure.NewContainer(endure.DebugLevel, endure.RetryOnFail(true)) + container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.DebugLevel)) if err != nil { t.Fatal(err) } - vp := &config.ViperProvider{} + vp := &config.Viper{} vp.Path = ".rr.yaml" vp.Prefix = "rr" err = container.Register(vp) diff --git a/plugins/config/tests/plugin1.go b/plugins/config/tests/plugin1.go index 7c5f2afd..a276c15f 100755 --- a/plugins/config/tests/plugin1.go +++ b/plugins/config/tests/plugin1.go @@ -23,11 +23,11 @@ type ServiceConfig struct { } type Foo struct { - configProvider config.Provider + configProvider config.Configurer } // Depends on S2 and DB (S3 in the current case) -func (f *Foo) Init(p config.Provider) error { +func (f *Foo) Init(p config.Configurer) error { f.configProvider = p return nil } |