diff options
author | Valery Piashchynski <[email protected]> | 2021-09-16 21:46:50 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2021-09-16 21:46:50 +0300 |
commit | 3581b45f237a3f7aa29591ceb2bf6f4a4642a2f5 (patch) | |
tree | e723b19ec1ac16b7ccc7b3c2da69d4a416d63d81 /tests/plugins/config | |
parent | 337d292dd2d6ff0a555098b1970d8194d8df8bc2 (diff) | |
parent | 823d831b57b75f70c7c3bbbee355f2016633bb3b (diff) |
[#803]: feat(plugins): move plugins to a separate repositoryv2.5.0-alpha.2
[#803]: feat(plugins): move plugins to a separate repository
Diffstat (limited to 'tests/plugins/config')
-rwxr-xr-x | tests/plugins/config/config_test.go | 272 | ||||
-rwxr-xr-x | tests/plugins/config/configs/.rr-env.yaml | 24 | ||||
-rwxr-xr-x | tests/plugins/config/configs/.rr.yaml | 24 | ||||
-rwxr-xr-x | tests/plugins/config/plugin1.go | 96 | ||||
-rwxr-xr-x | tests/plugins/config/plugin2.go | 50 | ||||
-rwxr-xr-x | tests/plugins/config/plugin3.go | 34 |
6 files changed, 0 insertions, 500 deletions
diff --git a/tests/plugins/config/config_test.go b/tests/plugins/config/config_test.go deleted file mode 100755 index 87ab1eaa..00000000 --- a/tests/plugins/config/config_test.go +++ /dev/null @@ -1,272 +0,0 @@ -package config - -import ( - "os" - "os/signal" - "testing" - "time" - - endure "github.com/spiral/endure/pkg/container" - "github.com/spiral/roadrunner/v2/plugins/config" - "github.com/spiral/roadrunner/v2/plugins/logger" - "github.com/spiral/roadrunner/v2/plugins/rpc" - "github.com/stretchr/testify/assert" -) - -func TestViperProvider_Init(t *testing.T) { - container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel)) - if err != nil { - t.Fatal(err) - } - vp := &config.Viper{} - vp.Path = "configs/.rr.yaml" - vp.Prefix = "rr" - vp.Flags = nil - - err = container.Register(vp) - if err != nil { - t.Fatal(err) - } - - err = container.Register(&Foo{}) - if err != nil { - t.Fatal(err) - } - - err = container.Init() - if err != nil { - t.Fatal(err) - } - - errCh, err := container.Serve() - if err != nil { - t.Fatal(err) - } - - // stop by CTRL+C - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) - - tt := time.NewTicker(time.Second * 2) - defer tt.Stop() - - for { - select { - case e := <-errCh: - assert.NoError(t, e.Error) - assert.NoError(t, container.Stop()) - return - case <-c: - er := container.Stop() - assert.NoError(t, er) - return - case <-tt.C: - assert.NoError(t, container.Stop()) - return - } - } -} - -func TestConfigOverwriteFail(t *testing.T) { - container, err := endure.NewContainer(nil, endure.RetryOnFail(false), endure.SetLogLevel(endure.ErrorLevel)) - if err != nil { - t.Fatal(err) - } - vp := &config.Viper{} - vp.Path = "configs/.rr.yaml" - vp.Prefix = "rr" - vp.Flags = []string{"rpc.listen=tcp//not_exist"} - - err = container.RegisterAll( - &logger.ZapLogger{}, - &rpc.Plugin{}, - vp, - &Foo2{}, - ) - assert.NoError(t, err) - - err = container.Init() - assert.Error(t, err) -} - -func TestConfigOverwriteValid(t *testing.T) { - container, err := endure.NewContainer(nil, endure.RetryOnFail(false), endure.SetLogLevel(endure.ErrorLevel)) - if err != nil { - t.Fatal(err) - } - vp := &config.Viper{} - vp.Path = "configs/.rr.yaml" - vp.Prefix = "rr" - vp.Flags = []string{"rpc.listen=tcp://127.0.0.1:36643"} - - err = container.RegisterAll( - &logger.ZapLogger{}, - &rpc.Plugin{}, - vp, - &Foo2{}, - ) - assert.NoError(t, err) - - err = container.Init() - assert.NoError(t, err) - - errCh, err := container.Serve() - assert.NoError(t, err) - - // stop by CTRL+C - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) - - tt := time.NewTicker(time.Second * 3) - defer tt.Stop() - - for { - select { - case e := <-errCh: - assert.NoError(t, e.Error) - assert.NoError(t, container.Stop()) - return - case <-c: - er := container.Stop() - assert.NoError(t, er) - return - case <-tt.C: - assert.NoError(t, container.Stop()) - return - } - } -} - -func TestConfigEnvVariables(t *testing.T) { - container, err := endure.NewContainer(nil, endure.RetryOnFail(false), endure.SetLogLevel(endure.ErrorLevel)) - if err != nil { - t.Fatal(err) - } - - err = os.Setenv("SUPER_RPC_ENV", "tcp://127.0.0.1:36643") - assert.NoError(t, err) - - vp := &config.Viper{} - vp.Path = "configs/.rr-env.yaml" - vp.Prefix = "rr" - - err = container.RegisterAll( - &logger.ZapLogger{}, - &rpc.Plugin{}, - vp, - &Foo2{}, - ) - assert.NoError(t, err) - - err = container.Init() - assert.NoError(t, err) - - errCh, err := container.Serve() - assert.NoError(t, err) - - // stop by CTRL+C - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) - - tt := time.NewTicker(time.Second * 3) - defer tt.Stop() - - for { - select { - case e := <-errCh: - assert.NoError(t, e.Error) - assert.NoError(t, container.Stop()) - return - case <-c: - er := container.Stop() - assert.NoError(t, er) - return - case <-tt.C: - assert.NoError(t, container.Stop()) - return - } - } -} - -func TestConfigEnvVariablesFail(t *testing.T) { - container, err := endure.NewContainer(nil, endure.RetryOnFail(false), endure.SetLogLevel(endure.ErrorLevel)) - if err != nil { - t.Fatal(err) - } - - err = os.Setenv("SUPER_RPC_ENV", "tcp://127.0.0.1:6065") - assert.NoError(t, err) - - vp := &config.Viper{} - vp.Path = "configs/.rr-env.yaml" - vp.Prefix = "rr" - - err = container.RegisterAll( - &logger.ZapLogger{}, - &rpc.Plugin{}, - vp, - &Foo2{}, - ) - assert.NoError(t, err) - - err = container.Init() - assert.NoError(t, err) - - _, err = container.Serve() - assert.Error(t, err) -} - -func TestConfigProvider_GeneralSection(t *testing.T) { - container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel)) - if err != nil { - t.Fatal(err) - } - vp := &config.Viper{} - vp.Path = "configs/.rr.yaml" - vp.Prefix = "rr" - vp.Flags = nil - vp.CommonConfig = &config.General{GracefulTimeout: time.Second * 10} - - err = container.Register(vp) - if err != nil { - t.Fatal(err) - } - - err = container.Register(&Foo3{}) - if err != nil { - t.Fatal(err) - } - - err = container.Init() - if err != nil { - t.Fatal(err) - } - - errCh, err := container.Serve() - if err != nil { - t.Fatal(err) - } - - // stop by CTRL+C - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) - - tt := time.NewTicker(time.Second * 2) - defer tt.Stop() - - for { - select { - case e := <-errCh: - assert.NoError(t, e.Error) - assert.NoError(t, container.Stop()) - return - case <-c: - er := container.Stop() - assert.NoError(t, er) - return - case <-tt.C: - assert.NoError(t, container.Stop()) - return - } - } -} diff --git a/tests/plugins/config/configs/.rr-env.yaml b/tests/plugins/config/configs/.rr-env.yaml deleted file mode 100755 index 3cacb5d0..00000000 --- a/tests/plugins/config/configs/.rr-env.yaml +++ /dev/null @@ -1,24 +0,0 @@ -rpc: - listen: ${SUPER_RPC_ENV} - -logs: - mode: development - level: error - -reload: - interval: 1s - patterns: [ ".php" ] - services: - http: - recursive: true - ignore: [ "vendor" ] - patterns: [ ".php", ".go",".md", ] - dirs: [ "." ] - jobs: - recursive: false - ignore: [ "service/metrics" ] - dirs: [ "./jobs" ] - rpc: - recursive: true - patterns: [ ".json" ] - dirs: [ "" ] diff --git a/tests/plugins/config/configs/.rr.yaml b/tests/plugins/config/configs/.rr.yaml deleted file mode 100755 index 575cdd33..00000000 --- a/tests/plugins/config/configs/.rr.yaml +++ /dev/null @@ -1,24 +0,0 @@ -rpc: - listen: tcp://127.0.0.1:6060 - -logs: - mode: development - level: error - -reload: - interval: 1s - patterns: [".php"] - services: - http: - recursive: true - ignore: ["vendor"] - patterns: [".php", ".go",".md",] - dirs: ["."] - jobs: - recursive: false - ignore: ["service/metrics"] - dirs: ["./jobs"] - rpc: - recursive: true - patterns: [".json"] - dirs: [""] diff --git a/tests/plugins/config/plugin1.go b/tests/plugins/config/plugin1.go deleted file mode 100755 index 08a48a4f..00000000 --- a/tests/plugins/config/plugin1.go +++ /dev/null @@ -1,96 +0,0 @@ -package config - -import ( - "time" - - "github.com/spiral/errors" - "github.com/spiral/roadrunner/v2/plugins/config" -) - -type AllConfig struct { - RPC struct { - Listen string `mapstructure:"listen"` - } `mapstructure:"rpc"` - Reload struct { - Enabled bool `mapstructure:"enabled"` - Interval string `mapstructure:"interval"` - Patterns []string `mapstructure:"patterns"` - Services struct { - HTTP struct { - Recursive bool `mapstructure:"recursive"` - Ignore []string `mapstructure:"ignore"` - Patterns []string `mapstructure:"patterns"` - Dirs []string `mapstructure:"dirs"` - } `mapstructure:"http"` - Jobs struct { - Recursive bool `mapstructure:"recursive"` - Ignore []string `mapstructure:"ignore"` - Dirs []string `mapstructure:"dirs"` - } `mapstructure:"jobs"` - RPC struct { - Recursive bool `mapstructure:"recursive"` - Patterns []string `mapstructure:"patterns"` - Dirs []string `mapstructure:"dirs"` - } `mapstructure:"rpc"` - } `mapstructure:"services"` - } `mapstructure:"reload"` -} - -// ReloadConfig is a Reload configuration point. -type ReloadConfig struct { - Interval time.Duration - Patterns []string - Services map[string]ServiceConfig -} - -type ServiceConfig struct { - Enabled bool - Recursive bool - Patterns []string - Dirs []string - Ignore []string -} - -type Foo struct { - configProvider config.Configurer -} - -// Depends on S2 and DB (S3 in the current case) -func (f *Foo) Init(p config.Configurer) error { - f.configProvider = p - return nil -} - -func (f *Foo) Serve() chan error { - const op = errors.Op("foo_plugin_serve") - errCh := make(chan error, 1) - - r := &ReloadConfig{} - err := f.configProvider.UnmarshalKey("reload", r) - if err != nil { - errCh <- err - } - - if len(r.Patterns) == 0 { - errCh <- errors.E(op, errors.Str("should be at least one pattern, but got 0")) - return errCh - } - - var allCfg AllConfig - err = f.configProvider.Unmarshal(&allCfg) - if err != nil { - errCh <- errors.E(op, errors.Str("should be at least one pattern, but got 0")) - return errCh - } - - if allCfg.RPC.Listen != "tcp://127.0.0.1:6060" { - errCh <- errors.E(op, errors.Str("RPC.Listen should be parsed")) - return errCh - } - - return errCh -} - -func (f *Foo) Stop() error { - return nil -} diff --git a/tests/plugins/config/plugin2.go b/tests/plugins/config/plugin2.go deleted file mode 100755 index 8c6f36c1..00000000 --- a/tests/plugins/config/plugin2.go +++ /dev/null @@ -1,50 +0,0 @@ -package config - -import ( - "github.com/spiral/errors" - "github.com/spiral/roadrunner/v2/plugins/config" -) - -type Foo2 struct { - configProvider config.Configurer -} - -// Depends on S2 and DB (S3 in the current case) -func (f *Foo2) Init(p config.Configurer) error { - f.configProvider = p - return nil -} - -func (f *Foo2) Serve() chan error { - const op = errors.Op("foo_plugin_serve") - errCh := make(chan error, 1) - - r := &ReloadConfig{} - err := f.configProvider.UnmarshalKey("reload", r) - if err != nil { - errCh <- err - } - - if len(r.Patterns) == 0 { - errCh <- errors.E(op, errors.Str("should be at least one pattern, but got 0")) - return errCh - } - - var allCfg AllConfig - err = f.configProvider.Unmarshal(&allCfg) - if err != nil { - errCh <- errors.E(op, errors.Str("should be at least one pattern, but got 0")) - return errCh - } - - if allCfg.RPC.Listen != "tcp://127.0.0.1:36643" { - errCh <- errors.E(op, errors.Str("RPC.Listen should be overwritten")) - return errCh - } - - return errCh -} - -func (f *Foo2) Stop() error { - return nil -} diff --git a/tests/plugins/config/plugin3.go b/tests/plugins/config/plugin3.go deleted file mode 100755 index 41b79259..00000000 --- a/tests/plugins/config/plugin3.go +++ /dev/null @@ -1,34 +0,0 @@ -package config - -import ( - "time" - - "github.com/spiral/errors" - "github.com/spiral/roadrunner/v2/plugins/config" -) - -type Foo3 struct { - configProvider config.Configurer -} - -// Depends on S2 and DB (S3 in the current case) -func (f *Foo3) Init(p config.Configurer) error { - f.configProvider = p - return nil -} - -func (f *Foo3) Serve() chan error { - const op = errors.Op("foo_plugin_serve") - errCh := make(chan error, 1) - - if f.configProvider.GetCommonConfig().GracefulTimeout != time.Second*10 { - errCh <- errors.E(op, errors.Str("GracefulTimeout should be eq to 10 seconds")) - return errCh - } - - return errCh -} - -func (f *Foo3) Stop() error { - return nil -} |