summaryrefslogtreecommitdiff
path: root/tests/plugins/config/config_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/plugins/config/config_test.go')
-rwxr-xr-xtests/plugins/config/config_test.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/plugins/config/config_test.go b/tests/plugins/config/config_test.go
index 364960db..dc387086 100755
--- a/tests/plugins/config/config_test.go
+++ b/tests/plugins/config/config_test.go
@@ -8,6 +8,8 @@ import (
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"
)
@@ -19,6 +21,8 @@ func TestViperProvider_Init(t *testing.T) {
vp := &config.Viper{}
vp.Path = ".rr.yaml"
vp.Prefix = "rr"
+ vp.Flags = nil
+
err = container.Register(vp)
if err != nil {
t.Fatal(err)
@@ -62,3 +66,73 @@ func TestViperProvider_Init(t *testing.T) {
}
}
}
+
+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 = ".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 = ".rr.yaml"
+ vp.Prefix = "rr"
+ vp.Flags = []string{"rpc.listen=tcp://localhost:6061"}
+
+ 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
+ }
+ }
+}