diff options
author | Valery Piashchynski <[email protected]> | 2021-04-04 19:31:06 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-04-04 19:31:06 +0300 |
commit | c6b123af6464c3c6fd79bf1fc28da71c300eb7b3 (patch) | |
tree | ed9c1f087e68a2c70ac002466c233469563fc5e9 /tests/plugins/logger | |
parent | 10a153e9df62bcbdf77c5b5a63daf5ea7b792495 (diff) |
- Update CHANGELOG
- Check log event by logger (mocked)
- Modify Stderr event to be as INFO
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'tests/plugins/logger')
-rw-r--r-- | tests/plugins/logger/configs/.rr-raw-mode.yaml | 12 | ||||
-rw-r--r-- | tests/plugins/logger/logger_test.go | 129 |
2 files changed, 72 insertions, 69 deletions
diff --git a/tests/plugins/logger/configs/.rr-raw-mode.yaml b/tests/plugins/logger/configs/.rr-raw-mode.yaml index 0e62ab95..fba25945 100644 --- a/tests/plugins/logger/configs/.rr-raw-mode.yaml +++ b/tests/plugins/logger/configs/.rr-raw-mode.yaml @@ -4,12 +4,12 @@ server: http: address: 127.0.0.1:34999 - maxRequestSize: 1024 + max_requestSize: 1024 pool: - numWorkers: 1 - maxJobs: 0 - allocateTimeout: 10s - destroyTimeout: 10s + num_workers: 1 + max_jobs: 0 + allocate_timeout: 10s + destroy_timeout: 10s logs: - mode: raw
\ No newline at end of file + mode: raw diff --git a/tests/plugins/logger/logger_test.go b/tests/plugins/logger/logger_test.go index f212cc8a..d2877781 100644 --- a/tests/plugins/logger/logger_test.go +++ b/tests/plugins/logger/logger_test.go @@ -7,14 +7,14 @@ import ( "syscall" "testing" - "github.com/kami-zh/go-capturer" - + "github.com/golang/mock/gomock" 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/spiral/roadrunner/v2/tests/mocks" "github.com/stretchr/testify/assert" ) @@ -78,71 +78,74 @@ func TestLogger(t *testing.T) { } func TestLoggerRawErr(t *testing.T) { - out := capturer.CaptureOutput(func() { - cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) - assert.NoError(t, err) - - // config plugin - cfg := &config.Viper{} - cfg.Path = "configs/.rr-raw-mode.yaml" - cfg.Prefix = "rr" - - err = cont.RegisterAll( - cfg, - &logger.ZapLogger{}, - &server.Plugin{}, - &http.Plugin{}, - ) - assert.NoError(t, err) - - err = cont.Init() - if err != nil { - t.Fatal(err) - } + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) + assert.NoError(t, err) + + // config plugin + cfg := &config.Viper{} + cfg.Path = "configs/.rr-raw-mode.yaml" + cfg.Prefix = "rr" + + controller := gomock.NewController(t) + mockLogger := mocks.NewMockLogger(controller) + + mockLogger.EXPECT().Debug("worker destructed", "pid", gomock.Any()).MinTimes(1) + mockLogger.EXPECT().Info("{\"field\": \"value\"}").MinTimes(1) + mockLogger.EXPECT().Debug("worker constructed", "pid", gomock.Any()).MinTimes(1) + + err = cont.RegisterAll( + cfg, + mockLogger, + &server.Plugin{}, + &http.Plugin{}, + ) + assert.NoError(t, err) + + err = cont.Init() + if err != nil { + t.Fatal(err) + } + + ch, err := cont.Serve() + assert.NoError(t, err) + + sig := make(chan os.Signal, 1) + signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) - ch, err := cont.Serve() - assert.NoError(t, err) - - sig := make(chan os.Signal, 1) - signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) - - wg := &sync.WaitGroup{} - wg.Add(1) - - stopCh := make(chan struct{}, 1) - - go func() { - defer wg.Done() - for { - select { - case e := <-ch: - assert.Fail(t, "error", e.Error.Error()) - err = cont.Stop() - if err != nil { - assert.FailNow(t, "error", err.Error()) - } - case <-sig: - err = cont.Stop() - if err != nil { - assert.FailNow(t, "error", err.Error()) - } - return - case <-stopCh: - // timeout - err = cont.Stop() - if err != nil { - assert.FailNow(t, "error", err.Error()) - } - return + wg := &sync.WaitGroup{} + wg.Add(1) + + stopCh := make(chan struct{}, 1) + + go func() { + defer wg.Done() + for { + select { + case e := <-ch: + assert.Fail(t, "error", e.Error.Error()) + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + case <-sig: + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) } + return + case <-stopCh: + // timeout + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + return } - }() - - stopCh <- struct{}{} - wg.Wait() - }) + } + }() - assert.Contains(t, out, "\n{\"field\": \"value\"}\n") + stopCh <- struct{}{} + wg.Wait() } func TestLoggerNoConfig(t *testing.T) { |