diff options
author | bricelalu <[email protected]> | 2021-04-03 22:28:30 +0200 |
---|---|---|
committer | bricelalu <[email protected]> | 2021-04-03 22:28:30 +0200 |
commit | 22797c86a9c346037adc349a89d51ecdb22e5550 (patch) | |
tree | 84fab02d36a634c612e0b62c07d64578dcb35cda /tests/plugins/logger | |
parent | 0744265c45840ff7f3f5802f0f5d9073939e707c (diff) |
Update test for Logger 'raw' mode
Diffstat (limited to 'tests/plugins/logger')
-rw-r--r-- | tests/plugins/logger/configs/.rr-raw-mode.yaml | 13 | ||||
-rw-r--r-- | tests/plugins/logger/logger_test.go | 66 |
2 files changed, 49 insertions, 30 deletions
diff --git a/tests/plugins/logger/configs/.rr-raw-mode.yaml b/tests/plugins/logger/configs/.rr-raw-mode.yaml index 77bd2f59..0e62ab95 100644 --- a/tests/plugins/logger/configs/.rr-raw-mode.yaml +++ b/tests/plugins/logger/configs/.rr-raw-mode.yaml @@ -1,2 +1,15 @@ +server: + command: "php ../../raw-error.php" + relay: "pipes" + +http: + address: 127.0.0.1:34999 + maxRequestSize: 1024 + pool: + numWorkers: 1 + maxJobs: 0 + allocateTimeout: 10s + destroyTimeout: 10s + logs: mode: raw
\ No newline at end of file diff --git a/tests/plugins/logger/logger_test.go b/tests/plugins/logger/logger_test.go index a1bc0f4d..f212cc8a 100644 --- a/tests/plugins/logger/logger_test.go +++ b/tests/plugins/logger/logger_test.go @@ -4,6 +4,7 @@ import ( "os" "os/signal" "sync" + "syscall" "testing" "github.com/kami-zh/go-capturer" @@ -76,57 +77,62 @@ func TestLogger(t *testing.T) { wg.Wait() } -func TestLoggerRawMode(t *testing.T) { +func TestLoggerRawErr(t *testing.T) { out := capturer.CaptureOutput(func() { - container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel)) - if err != nil { - t.Fatal(err) - } + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) + assert.NoError(t, err) + // config plugin - vp := &config.Viper{} - vp.Path = "configs/.rr-raw-mode.yaml" - vp.Prefix = "rr" + cfg := &config.Viper{} + cfg.Path = "configs/.rr-raw-mode.yaml" + cfg.Prefix = "rr" - err = container.RegisterAll( - vp, - &Plugin{}, + err = cont.RegisterAll( + cfg, &logger.ZapLogger{}, + &server.Plugin{}, + &http.Plugin{}, ) assert.NoError(t, err) - err = container.Init() - if err != nil { - t.Fatal(err) - } - - errCh, err := container.Serve() + err = cont.Init() if err != nil { t.Fatal(err) } - // stop by CTRL+C - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) + ch, err := cont.Serve() + assert.NoError(t, err) - stopCh := make(chan struct{}, 1) + 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 := <-errCh: - assert.NoError(t, e.Error) - assert.NoError(t, container.Stop()) - return - case <-c: - err = container.Stop() - assert.NoError(t, err) + 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: - assert.NoError(t, container.Stop()) + // timeout + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } return } } @@ -136,7 +142,7 @@ func TestLoggerRawMode(t *testing.T) { wg.Wait() }) - assert.Contains(t, out, `{"field": "value"}`) + assert.Contains(t, out, "\n{\"field\": \"value\"}\n") } func TestLoggerNoConfig(t *testing.T) { |