From cf3e341207893d62bae8a5671118401f745a8f08 Mon Sep 17 00:00:00 2001 From: valentin v / vvval Date: Thu, 21 Feb 2019 16:37:10 +0300 Subject: Add tests for MaxRequest merging --- service/http/config_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'service/http/config_test.go') 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, + }, + }, + } +} -- cgit v1.2.3