summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorvalentin v / vvval <[email protected]>2019-02-21 16:37:10 +0300
committervalentin v / vvval <[email protected]>2019-02-21 16:37:10 +0300
commitcf3e341207893d62bae8a5671118401f745a8f08 (patch)
tree66fd3bbbdf5b456af5781b8f17f81d9312062aac /service
parent46a52a8691e83c81a6d12183eddf188b5d15f011 (diff)
Add tests for MaxRequest merging
Diffstat (limited to 'service')
-rw-r--r--service/http/config.go6
-rw-r--r--service/http/config_test.go51
2 files changed, 56 insertions, 1 deletions
diff --git a/service/http/config.go b/service/http/config.go
index 711939b7..7549cb6c 100644
--- a/service/http/config.go
+++ b/service/http/config.go
@@ -17,8 +17,11 @@ type Config struct {
// SSL defines https server options.
SSL SSLConfig
+ // MaxRequest specified max size for payload body in megabytes, set 0 to unlimited.
+ // Deprecated: use `maxRequestSize` instead
+ MaxRequest int64
+
// MaxRequestSize specified max size for payload body in megabytes, set 0 to unlimited.
- MaxRequest int64
MaxRequestSize int64
// Uploads configures uploads configuration.
@@ -118,6 +121,7 @@ func (c *Config) Valid() error {
return nil
}
+// Perform merge operations for deprecated params to provide backward compatibility
func (c *Config) mergeBackwardCompatibility() {
if c.MaxRequestSize == 0 && c.MaxRequest != 0 {
c.MaxRequestSize = c.MaxRequest
diff --git a/service/http/config_test.go b/service/http/config_test.go
index 4cd2783f..7c9d629a 100644
--- a/service/http/config_test.go
+++ b/service/http/config_test.go
@@ -222,3 +222,54 @@ func Test_Config_InvalidAddress(t *testing.T) {
assert.Error(t, cfg.Valid())
}
+
+func Test_Config_MergeBackwardCompatibility_MaxRequestSize(t *testing.T) {
+ c := newTestBackwardCompatibilityConfig()
+ cfg := mockCfg{cfg: `{"maxRequestSize":512}`}
+ assert.NoError(t, c.Valid())
+ assert.NoError(t, c.Hydrate(&cfg))
+ assert.Equal(t, int64(512), int64(c.MaxRequestSize))
+
+ c = newTestBackwardCompatibilityConfig()
+ cfg = mockCfg{cfg: `{"maxRequestSize":256,"maxRequest":1024}`}
+ assert.NoError(t, c.Valid())
+ assert.NoError(t, c.Hydrate(&cfg))
+ assert.Equal(t, int64(256), int64(c.MaxRequestSize))
+
+ c = newTestBackwardCompatibilityConfig()
+ cfg = mockCfg{cfg: `{"maxRequestSize":256,"maxRequest":0}`}
+ assert.NoError(t, c.Valid())
+ assert.NoError(t, c.Hydrate(&cfg))
+ assert.Equal(t, int64(256), int64(c.MaxRequestSize))
+
+ c = newTestBackwardCompatibilityConfig()
+ cfg = mockCfg{cfg: `{"maxRequest":1024}`}
+ assert.NoError(t, c.Valid())
+ assert.NoError(t, c.Hydrate(&cfg))
+ assert.Equal(t, int64(1024), int64(c.MaxRequestSize))
+
+ c = newTestBackwardCompatibilityConfig()
+ cfg = mockCfg{cfg: `{"maxRequestSize":0,"maxRequest":1024}`}
+ assert.NoError(t, c.Valid())
+ assert.NoError(t, c.Hydrate(&cfg))
+ assert.Equal(t, int64(1024), int64(c.MaxRequestSize))
+}
+
+func newTestBackwardCompatibilityConfig() *Config {
+ return &Config{
+ Address: ":8080",
+ Uploads: &UploadsConfig{
+ Dir: os.TempDir(),
+ Forbid: []string{".go"},
+ },
+ Workers: &roadrunner.ServerConfig{
+ Command: "php tests/client.php echo pipes",
+ Relay: "pipes",
+ Pool: &roadrunner.Config{
+ NumWorkers: 1,
+ AllocateTimeout: time.Second,
+ DestroyTimeout: time.Second,
+ },
+ },
+ }
+}