summaryrefslogtreecommitdiff
path: root/tests/plugins
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-09 13:32:34 +0300
committerValery Piashchynski <[email protected]>2021-06-09 13:32:34 +0300
commit3ec3306730455b6c5c423d130ebc322757661487 (patch)
tree1acfe544effb563a06e133a13be1faac6b3fddbb /tests/plugins
parenta723cedba199a1c50dca05630b53139ee456ace8 (diff)
- Add support for the file logger with log rotation and compression
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'tests/plugins')
-rw-r--r--tests/plugins/http/configs/.rr-init.yaml6
-rw-r--r--tests/plugins/logger/configs/.rr-file-logger.yaml23
-rw-r--r--tests/plugins/logger/logger_test.go97
3 files changed, 117 insertions, 9 deletions
diff --git a/tests/plugins/http/configs/.rr-init.yaml b/tests/plugins/http/configs/.rr-init.yaml
index 1671c3c0..02cb1636 100644
--- a/tests/plugins/http/configs/.rr-init.yaml
+++ b/tests/plugins/http/configs/.rr-init.yaml
@@ -3,17 +3,13 @@ rpc:
server:
command: "php ../../http/client.php echo pipes"
- user: ""
- group: ""
- env:
- "RR_HTTP": "true"
relay: "pipes"
relay_timeout: "20s"
http:
address: 127.0.0.1:15395
max_request_size: 1024
- middleware: [ "" ]
+ middleware: [ ]
uploads:
forbid: [ ".php", ".exe", ".bat" ]
trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]
diff --git a/tests/plugins/logger/configs/.rr-file-logger.yaml b/tests/plugins/logger/configs/.rr-file-logger.yaml
new file mode 100644
index 00000000..49c30d02
--- /dev/null
+++ b/tests/plugins/logger/configs/.rr-file-logger.yaml
@@ -0,0 +1,23 @@
+server:
+ command: "php ../../http/client.php echo pipes"
+ relay: "pipes"
+ relay_timeout: "20s"
+
+http:
+ address: 127.0.0.1:54224
+ max_request_size: 1024
+ middleware: [ ]
+ uploads:
+ forbid: [ ".php", ".exe", ".bat" ]
+ trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]
+ pool:
+ num_workers: 2
+ max_jobs: 0
+ allocate_timeout: 60s
+ destroy_timeout: 60s
+
+logs:
+ mode: development
+ level: debug
+ file_logger_options:
+ log_output: "test.log"
diff --git a/tests/plugins/logger/logger_test.go b/tests/plugins/logger/logger_test.go
index d2877781..9e3fa4da 100644
--- a/tests/plugins/logger/logger_test.go
+++ b/tests/plugins/logger/logger_test.go
@@ -1,16 +1,19 @@
package logger
import (
+ "net/http"
"os"
"os/signal"
+ "strings"
"sync"
"syscall"
"testing"
+ "time"
"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"
+ httpPlugin "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"
@@ -19,7 +22,7 @@ import (
)
func TestLogger(t *testing.T) {
- container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
+ container, err := endure.NewContainer(nil, endure.RetryOnFail(false), endure.SetLogLevel(endure.ErrorLevel))
if err != nil {
t.Fatal(err)
}
@@ -97,7 +100,7 @@ func TestLoggerRawErr(t *testing.T) {
cfg,
mockLogger,
&server.Plugin{},
- &http.Plugin{},
+ &httpPlugin.Plugin{},
)
assert.NoError(t, err)
@@ -222,7 +225,7 @@ func TestLoggerNoConfig2(t *testing.T) {
vp,
&rpc.Plugin{},
&logger.ZapLogger{},
- &http.Plugin{},
+ &httpPlugin.Plugin{},
&server.Plugin{},
)
assert.NoError(t, err)
@@ -268,3 +271,89 @@ func TestLoggerNoConfig2(t *testing.T) {
stopCh <- struct{}{}
wg.Wait()
}
+
+func TestFileLogger(t *testing.T) {
+ container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
+ if err != nil {
+ t.Fatal(err)
+ }
+ // config plugin
+ vp := &config.Viper{}
+ vp.Path = "configs/.rr-file-logger.yaml"
+ vp.Prefix = "rr"
+
+ err = container.RegisterAll(
+ vp,
+ &rpc.Plugin{},
+ &logger.ZapLogger{},
+ &httpPlugin.Plugin{},
+ &server.Plugin{},
+ )
+ 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
+ }
+ }
+ }()
+
+ time.Sleep(time.Second * 2)
+ t.Run("HTTPEchoReq", httpEcho)
+
+ f, err := os.ReadFile("test.log")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ strings.Contains(string(f), "worker constructed")
+ strings.Contains(string(f), "201 GET")
+
+ _ = os.Remove("test.log")
+
+ stopCh <- struct{}{}
+ wg.Wait()
+}
+
+func httpEcho(t *testing.T) {
+ req, err := http.NewRequest(http.MethodGet, "http://localhost:54224?hello=world", nil)
+ assert.NoError(t, err)
+
+ r, err := http.DefaultClient.Do(req)
+ assert.NoError(t, err)
+ assert.Equal(t, http.StatusCreated, r.StatusCode)
+
+ err = r.Body.Close()
+ assert.NoError(t, err)
+}