summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-01-21 13:25:36 +0300
committerValery Piashchynski <[email protected]>2021-01-21 13:25:36 +0300
commit7da6c78449776e1f3c6716250bca0b712a0423a4 (patch)
treef3512de66aca2bba408485a0ea2fc936c0e4fb9b /tests
parent0ff05b2732b4fd0783f959c94c54d7e39169f979 (diff)
Uniform all configs
Add debug server Check nil's for all plugin intialization
Diffstat (limited to 'tests')
-rw-r--r--tests/plugins/headers/configs/.rr-cors-headers.yaml1
-rw-r--r--tests/plugins/headers/configs/.rr-headers-init.yaml1
-rw-r--r--tests/plugins/headers/configs/.rr-req-headers.yaml1
-rw-r--r--tests/plugins/headers/configs/.rr-res-headers.yaml1
-rw-r--r--tests/plugins/http/configs/.rr-ssl.yaml6
-rw-r--r--tests/plugins/http/handler_test.go65
-rw-r--r--tests/plugins/http/uploads_config_test.go8
-rw-r--r--tests/plugins/http/uploads_test.go9
-rw-r--r--tests/plugins/static/config_test.go10
-rw-r--r--tests/psr-worker-bench.php33
10 files changed, 62 insertions, 73 deletions
diff --git a/tests/plugins/headers/configs/.rr-cors-headers.yaml b/tests/plugins/headers/configs/.rr-cors-headers.yaml
index 2e16ee66..c5ff576d 100644
--- a/tests/plugins/headers/configs/.rr-cors-headers.yaml
+++ b/tests/plugins/headers/configs/.rr-cors-headers.yaml
@@ -8,7 +8,6 @@ server:
relay_timeout: "20s"
http:
- debug: true
address: 127.0.0.1:22855
max_request_size: 1024
middleware: [ "headers" ]
diff --git a/tests/plugins/headers/configs/.rr-headers-init.yaml b/tests/plugins/headers/configs/.rr-headers-init.yaml
index 55b5b5a8..059df9ac 100644
--- a/tests/plugins/headers/configs/.rr-headers-init.yaml
+++ b/tests/plugins/headers/configs/.rr-headers-init.yaml
@@ -8,7 +8,6 @@ server:
relay_timeout: "20s"
http:
- debug: true
address: 127.0.0.1:33453
max_request_size: 1024
middleware: [ "headers" ]
diff --git a/tests/plugins/headers/configs/.rr-req-headers.yaml b/tests/plugins/headers/configs/.rr-req-headers.yaml
index fc38a74b..f0a52e17 100644
--- a/tests/plugins/headers/configs/.rr-req-headers.yaml
+++ b/tests/plugins/headers/configs/.rr-req-headers.yaml
@@ -8,7 +8,6 @@ server:
relay_timeout: "20s"
http:
- debug: true
address: 127.0.0.1:22655
max_request_size: 1024
middleware: [ "headers" ]
diff --git a/tests/plugins/headers/configs/.rr-res-headers.yaml b/tests/plugins/headers/configs/.rr-res-headers.yaml
index be9cfead..868b9746 100644
--- a/tests/plugins/headers/configs/.rr-res-headers.yaml
+++ b/tests/plugins/headers/configs/.rr-res-headers.yaml
@@ -8,7 +8,6 @@ server:
relay_timeout: "20s"
http:
- debug: true
address: 127.0.0.1:22455
max_request_size: 1024
middleware: [ "headers" ]
diff --git a/tests/plugins/http/configs/.rr-ssl.yaml b/tests/plugins/http/configs/.rr-ssl.yaml
index 182ac7ef..c3e45365 100644
--- a/tests/plugins/http/configs/.rr-ssl.yaml
+++ b/tests/plugins/http/configs/.rr-ssl.yaml
@@ -8,7 +8,6 @@ server:
relay_timeout: "20s"
http:
- debug: true
address: :8085
max_request_size: 1024
middleware: [ "" ]
@@ -26,13 +25,8 @@ http:
redirect: false
cert: fixtures/server.crt
key: fixtures/server.key
- # rootCa: root.crt
fcgi:
address: tcp://0.0.0.0:16920
- http2:
- enabled: false
- h2c: false
- maxConcurrentStreams: 128
logs:
mode: development
level: error \ No newline at end of file
diff --git a/tests/plugins/http/handler_test.go b/tests/plugins/http/handler_test.go
index 18558296..ee6f795d 100644
--- a/tests/plugins/http/handler_test.go
+++ b/tests/plugins/http/handler_test.go
@@ -13,6 +13,7 @@ import (
"github.com/spiral/roadrunner/v2/pkg/pipe"
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
+ "github.com/spiral/roadrunner/v2/plugins/http/config"
"github.com/stretchr/testify/assert"
"net/http"
@@ -34,7 +35,7 @@ func TestHandler_Echo(t *testing.T) {
t.Fatal(err)
}
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -65,7 +66,7 @@ func TestHandler_Echo(t *testing.T) {
}
func Test_HandlerErrors(t *testing.T) {
- _, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ _, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, nil)
@@ -88,7 +89,7 @@ func TestHandler_Headers(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -149,7 +150,7 @@ func TestHandler_Empty_User_Agent(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -209,7 +210,7 @@ func TestHandler_User_Agent(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -269,7 +270,7 @@ func TestHandler_Cookies(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -334,7 +335,7 @@ func TestHandler_JsonPayload_POST(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -398,7 +399,7 @@ func TestHandler_JsonPayload_PUT(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -458,7 +459,7 @@ func TestHandler_JsonPayload_PATCH(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -518,7 +519,7 @@ func TestHandler_FormData_POST(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -591,7 +592,7 @@ func TestHandler_FormData_POST_Overwrite(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -664,7 +665,7 @@ func TestHandler_FormData_POST_Form_UrlEncoded_Charset(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -736,7 +737,7 @@ func TestHandler_FormData_PUT(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -808,7 +809,7 @@ func TestHandler_FormData_PATCH(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -880,7 +881,7 @@ func TestHandler_Multipart_POST(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -994,7 +995,7 @@ func TestHandler_Multipart_PUT(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -1108,7 +1109,7 @@ func TestHandler_Multipart_PATCH(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -1224,7 +1225,7 @@ func TestHandler_Error(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -1270,7 +1271,7 @@ func TestHandler_Error2(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -1316,7 +1317,7 @@ func TestHandler_Error3(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -1375,7 +1376,7 @@ func TestHandler_ResponseDuration(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -1436,7 +1437,7 @@ func TestHandler_ResponseDurationDelayed(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -1496,7 +1497,7 @@ func TestHandler_ErrorDuration(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -1551,7 +1552,7 @@ func TestHandler_IP(t *testing.T) {
"fe80::/10",
}
- cidrs, err := httpPlugin.ParseCIDRs(trusted)
+ cidrs, err := config.ParseCIDRs(trusted)
assert.NoError(t, err)
assert.NotNil(t, cidrs)
@@ -1570,7 +1571,7 @@ func TestHandler_IP(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, cidrs, pool)
@@ -1612,7 +1613,7 @@ func TestHandler_XRealIP(t *testing.T) {
"fe80::/10",
}
- cidrs, err := httpPlugin.ParseCIDRs(trusted)
+ cidrs, err := config.ParseCIDRs(trusted)
assert.NoError(t, err)
assert.NotNil(t, cidrs)
@@ -1631,7 +1632,7 @@ func TestHandler_XRealIP(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, cidrs, pool)
@@ -1678,7 +1679,7 @@ func TestHandler_XForwardedFor(t *testing.T) {
"fe80::/10",
}
- cidrs, err := httpPlugin.ParseCIDRs(trusted)
+ cidrs, err := config.ParseCIDRs(trusted)
assert.NoError(t, err)
assert.NotNil(t, cidrs)
@@ -1697,7 +1698,7 @@ func TestHandler_XForwardedFor(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, cidrs, pool)
@@ -1743,7 +1744,7 @@ func TestHandler_XForwardedFor_NotTrustedRemoteIp(t *testing.T) {
"10.0.0.0/8",
}
- cidrs, err := httpPlugin.ParseCIDRs(trusted)
+ cidrs, err := config.ParseCIDRs(trusted)
assert.NoError(t, err)
assert.NotNil(t, cidrs)
@@ -1762,7 +1763,7 @@ func TestHandler_XForwardedFor_NotTrustedRemoteIp(t *testing.T) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, cidrs, pool)
@@ -1810,7 +1811,7 @@ func BenchmarkHandler_Listen_Echo(b *testing.B) {
pool.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
diff --git a/tests/plugins/http/uploads_config_test.go b/tests/plugins/http/uploads_config_test.go
index e76078ee..4f99b621 100644
--- a/tests/plugins/http/uploads_config_test.go
+++ b/tests/plugins/http/uploads_config_test.go
@@ -4,12 +4,12 @@ import (
"os"
"testing"
- httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
+ "github.com/spiral/roadrunner/v2/plugins/http/config"
"github.com/stretchr/testify/assert"
)
func TestFsConfig_Forbids(t *testing.T) {
- cfg := httpPlugin.UploadsConfig{Forbid: []string{".php"}}
+ cfg := config.Uploads{Forbid: []string{".php"}}
assert.True(t, cfg.Forbids("index.php"))
assert.True(t, cfg.Forbids("index.PHP"))
@@ -18,9 +18,9 @@ func TestFsConfig_Forbids(t *testing.T) {
}
func TestFsConfig_TmpFallback(t *testing.T) {
- cfg := httpPlugin.UploadsConfig{Dir: "test"}
+ cfg := config.Uploads{Dir: "test"}
assert.Equal(t, "test", cfg.TmpDir())
- cfg = httpPlugin.UploadsConfig{Dir: ""}
+ cfg = config.Uploads{Dir: ""}
assert.Equal(t, os.TempDir(), cfg.TmpDir())
}
diff --git a/tests/plugins/http/uploads_test.go b/tests/plugins/http/uploads_test.go
index 7bb25cbf..e03638d2 100644
--- a/tests/plugins/http/uploads_test.go
+++ b/tests/plugins/http/uploads_test.go
@@ -19,6 +19,7 @@ import (
"github.com/spiral/roadrunner/v2/pkg/pipe"
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
+ "github.com/spiral/roadrunner/v2/plugins/http/config"
"github.com/stretchr/testify/assert"
)
@@ -39,7 +40,7 @@ func TestHandler_Upload_File(t *testing.T) {
t.Fatal(err)
}
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -122,7 +123,7 @@ func TestHandler_Upload_NestedFile(t *testing.T) {
t.Fatal(err)
}
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -205,7 +206,7 @@ func TestHandler_Upload_File_NoTmpDir(t *testing.T) {
t.Fatal(err)
}
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: "-------",
Forbid: []string{},
}, nil, pool)
@@ -288,7 +289,7 @@ func TestHandler_Upload_File_Forbids(t *testing.T) {
t.Fatal(err)
}
- h, err := httpPlugin.NewHandler(1024, httpPlugin.UploadsConfig{
+ h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{".go"},
}, nil, pool)
diff --git a/tests/plugins/static/config_test.go b/tests/plugins/static/config_test.go
index f458eed3..d73fd845 100644
--- a/tests/plugins/static/config_test.go
+++ b/tests/plugins/static/config_test.go
@@ -8,7 +8,7 @@ import (
)
func TestConfig_Forbids(t *testing.T) {
- cfg := static.Config{Static: struct {
+ cfg := static.Config{Static: &struct {
Dir string
Forbid []string
Always []string
@@ -23,7 +23,7 @@ func TestConfig_Forbids(t *testing.T) {
}
func TestConfig_Valid(t *testing.T) {
- assert.NoError(t, (&static.Config{Static: struct {
+ assert.NoError(t, (&static.Config{Static: &struct {
Dir string
Forbid []string
Always []string
@@ -31,15 +31,15 @@ func TestConfig_Valid(t *testing.T) {
Response map[string]string
}{Dir: "./"}}).Valid())
- assert.Error(t, (&static.Config{Static: struct {
+ assert.Error(t, (&static.Config{Static: &struct {
Dir string
Forbid []string
Always []string
Request map[string]string
Response map[string]string
- }{Dir: "./config.go"}}).Valid())
+ }{Dir: "./http.go"}}).Valid())
- assert.Error(t, (&static.Config{Static: struct {
+ assert.Error(t, (&static.Config{Static: &struct {
Dir string
Forbid []string
Always []string
diff --git a/tests/psr-worker-bench.php b/tests/psr-worker-bench.php
index e6df81ad..3f6408bf 100644
--- a/tests/psr-worker-bench.php
+++ b/tests/psr-worker-bench.php
@@ -1,28 +1,25 @@
<?php
-/**
- * @var Goridge\RelayInterface $relay
- */
-use Spiral\Goridge;
+
use Spiral\RoadRunner;
+use Nyholm\Psr7\Factory;
ini_set('display_errors', 'stderr');
-require __DIR__ . "/vendor/autoload.php";
+include "vendor/autoload.php";
-$worker = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT));
-$psr7 = new RoadRunner\Http\PSR7Worker(
- $worker,
- new \Nyholm\Psr7\Factory\Psr17Factory(),
- new \Nyholm\Psr7\Factory\Psr17Factory(),
- new \Nyholm\Psr7\Factory\Psr17Factory()
+$worker = new RoadRunner\Http\PSR7Worker(
+ RoadRunner\Worker::create(),
+ new Factory\Psr17Factory(),
+ new Factory\Psr17Factory(),
+ new Factory\Psr17Factory()
);
-while ($req = $psr7->waitRequest()) {
+while ($req = $worker->waitRequest()) {
try {
- $resp = new \Nyholm\Psr7\Response();
- $resp->getBody()->write("hello world");
-
- $psr7->respond($resp);
+ $rsp = new \Nyholm\Psr7\Response();
+ $rsp->getBody()->write("hello world");
+ error_log("hello");
+ $worker->respond($rsp);
} catch (\Throwable $e) {
- $psr7->getWorker()->error((string)$e);
+ $worker->getWorker()->error((string)$e);
}
-}
+} \ No newline at end of file