summaryrefslogtreecommitdiff
path: root/tests/plugins/logger/logger_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/plugins/logger/logger_test.go')
-rw-r--r--tests/plugins/logger/logger_test.go125
1 files changed, 121 insertions, 4 deletions
diff --git a/tests/plugins/logger/logger_test.go b/tests/plugins/logger/logger_test.go
index 63f233ee..5be76b7a 100644
--- a/tests/plugins/logger/logger_test.go
+++ b/tests/plugins/logger/logger_test.go
@@ -8,7 +8,10 @@ import (
endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/roadrunner/v2/plugins/config"
+ "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/logger"
+ "github.com/spiral/roadrunner/v2/plugins/rpc"
+ "github.com/spiral/roadrunner/v2/plugins/server"
"github.com/stretchr/testify/assert"
)
@@ -19,22 +22,136 @@ func TestLogger(t *testing.T) {
}
// config plugin
vp := &config.Viper{}
- vp.Path = ".rr.yaml"
+ vp.Path = "configs/.rr.yaml"
vp.Prefix = "rr"
- err = container.Register(vp)
+
+ err = container.RegisterAll(
+ vp,
+ &Plugin{},
+ &logger.ZapLogger{},
+ )
+ assert.NoError(t, 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)
+
+ stopCh := make(chan struct{}, 1)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case e := <-errCh:
+ assert.NoError(t, e.Error)
+ assert.NoError(t, container.Stop())
+ return
+ case <-c:
+ err = container.Stop()
+ assert.NoError(t, err)
+ return
+ case <-stopCh:
+ assert.NoError(t, container.Stop())
+ return
+ }
+ }
+ }()
+
+ stopCh <- struct{}{}
+ wg.Wait()
+}
+
+func TestLoggerNoConfig(t *testing.T) {
+ container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.DebugLevel))
+ if err != nil {
+ t.Fatal(err)
+ }
+ // config plugin
+ vp := &config.Viper{}
+ vp.Path = "configs/.rr-no-logger.yaml"
+ vp.Prefix = "rr"
+
+ err = container.RegisterAll(
+ vp,
+ &Plugin{},
+ &logger.ZapLogger{},
+ )
+ assert.NoError(t, err)
+
+ err = container.Init()
if err != nil {
t.Fatal(err)
}
- err = container.Register(&Plugin{})
+ errCh, err := container.Serve()
if err != nil {
t.Fatal(err)
}
- err = container.Register(&logger.ZapLogger{})
+ // stop by CTRL+C
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, os.Interrupt)
+
+ stopCh := make(chan struct{}, 1)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case e := <-errCh:
+ assert.NoError(t, e.Error)
+ assert.NoError(t, container.Stop())
+ return
+ case <-c:
+ err = container.Stop()
+ assert.NoError(t, err)
+ return
+ case <-stopCh:
+ assert.NoError(t, container.Stop())
+ return
+ }
+ }
+ }()
+
+ stopCh <- struct{}{}
+ wg.Wait()
+}
+
+// Should no panic
+func TestLoggerNoConfig2(t *testing.T) {
+ container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.DebugLevel))
if err != nil {
t.Fatal(err)
}
+ // config plugin
+ vp := &config.Viper{}
+ vp.Path = "configs/.rr-no-logger2.yaml"
+ vp.Prefix = "rr"
+
+ err = container.RegisterAll(
+ vp,
+ &rpc.Plugin{},
+ &logger.ZapLogger{},
+ &http.Plugin{},
+ &server.Plugin{},
+ )
+ assert.NoError(t, err)
err = container.Init()
if err != nil {