diff options
-rwxr-xr-x | .github/workflows/ci-build.yml | 4 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | plugins/logger/tests/logger_test.go | 73 | ||||
-rw-r--r-- | plugins/logger/tests/plugin.go | 40 | ||||
-rw-r--r-- | plugins/logger/tests/plugin1.go | 26 |
5 files changed, 119 insertions, 27 deletions
diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index b8440443..e3e09d88 100755 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -69,6 +69,8 @@ jobs: go test -v -race ./plugins/rpc -tags=debug -coverprofile=rpc_config.txt -covermode=atomic go test -v -race ./plugins/rpc/tests -tags=debug -coverprofile=rpc.txt -covermode=atomic go test -v -race ./plugins/config/tests -tags=debug -coverprofile=plugin_config.txt -covermode=atomic + go test -v -race ./plugins/logger/tests -tags=debug -coverprofile=logger.txt -covermode=atomic + go test -v -race ./plugins/app/tests -tags=debug -coverprofile=app.txt -covermode=atomic - name: Run code coverage env: @@ -81,6 +83,8 @@ jobs: ./codecov-bash -f rpc_config.txt ./codecov-bash -f rpc.txt ./codecov-bash -f plugin_config.txt + ./codecov-bash -f logger.txt + ./codecov-bash -f app.txt fi golangci-check: @@ -3,4 +3,5 @@ test: go test -v -race -cover ./plugins/rpc -tags=debug go test -v -race -cover ./plugins/rpc/tests -tags=debug go test -v -race -cover ./plugins/config/tests -tags=debug - go test -v -race -cover ./plugins/app/tests -tags=debug
\ No newline at end of file + go test -v -race -cover ./plugins/app/tests -tags=debug + go test -v -race -cover ./plugins/logger/tests -tags=debug
\ No newline at end of file diff --git a/plugins/logger/tests/logger_test.go b/plugins/logger/tests/logger_test.go index ca8701d2..1df74c47 100644 --- a/plugins/logger/tests/logger_test.go +++ b/plugins/logger/tests/logger_test.go @@ -1 +1,74 @@ package tests + +import ( + "os" + "os/signal" + "testing" + "time" + + "github.com/spiral/endure" + "github.com/spiral/roadrunner/v2/plugins/config" + "github.com/spiral/roadrunner/v2/plugins/logger" + "github.com/stretchr/testify/assert" +) + +func TestLogger(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 = ".rr.yaml" + vp.Prefix = "rr" + err = container.Register(vp) + if err != nil { + t.Fatal(err) + } + + err = container.Register(&Plugin{}) + if err != nil { + t.Fatal(err) + } + + err = container.Register(&logger.ZapLogger{}) + 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) + + // stop after 10 seconds + tt := time.NewTicker(time.Second * 10) + + for { + select { + case e := <-errCh: + assert.NoError(t, e.Error) + assert.NoError(t, container.Stop()) + return + case <-c: + er := container.Stop() + if er != nil { + panic(er) + } + return + case <-tt.C: + tt.Stop() + assert.NoError(t, container.Stop()) + return + } + } +} diff --git a/plugins/logger/tests/plugin.go b/plugins/logger/tests/plugin.go new file mode 100644 index 00000000..75d2736d --- /dev/null +++ b/plugins/logger/tests/plugin.go @@ -0,0 +1,40 @@ +package tests + +import ( + "github.com/spiral/errors" + "github.com/spiral/roadrunner/v2/log" + "github.com/spiral/roadrunner/v2/plugins/config" +) + +type Plugin struct { + config config.Configurer + log log.Logger +} + +func (p1 *Plugin) Init(cfg config.Configurer, log log.Logger) error { + p1.config = cfg + p1.log = log + return nil +} + +func (p1 *Plugin) Serve() chan error { + errCh := make(chan error, 1) + p1.log.Error("error", "test", errors.E(errors.Str("test"))) + p1.log.Info("error", "test", errors.E(errors.Str("test"))) + p1.log.Debug("error", "test", errors.E(errors.Str("test"))) + p1.log.Warn("error", "test", errors.E(errors.Str("test"))) + + p1.log.Error("error", "test") + p1.log.Info("error", "test") + p1.log.Debug("error", "test") + p1.log.Warn("error", "test") + return errCh +} + +func (p1 *Plugin) Stop() error { + return nil +} + +func (p1 *Plugin) Name() string { + return "logger_plugin" +} diff --git a/plugins/logger/tests/plugin1.go b/plugins/logger/tests/plugin1.go deleted file mode 100644 index c4ca1371..00000000 --- a/plugins/logger/tests/plugin1.go +++ /dev/null @@ -1,26 +0,0 @@ -package tests - -import ( - "github.com/spiral/roadrunner/v2/plugins/config" - "github.com/spiral/roadrunner/v2/plugins/logger" -) - -type Plugin1 struct { - config config.Configurer - log *logger.ZapLogger -} - -func (p1 *Plugin1) Init(cfg config.Configurer, log *logger.ZapLogger) error { - p1.config = cfg - p1.log = log - return nil -} - -func (p1 *Plugin1) Serve() chan error { - errCh := make(chan error, 1) - return errCh -} - -func (p1 *Plugin1) Stop() error { - return nil -} |