diff options
author | Valery Piashchynski <[email protected]> | 2021-01-18 21:45:30 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-01-18 21:45:30 +0300 |
commit | 7e5d09e30986f7823b591c58eb858f100382b81f (patch) | |
tree | 887374374fc4aa91fe13df3b505273c8c858e12e /tests | |
parent | a9a206b31e272e0508fff496e9641c4db291ddb7 (diff) |
Fix NPE when .rr.yaml didn't contain HTTP section
Add tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/plugins/http/configs/.rr-no-http.yaml | 17 | ||||
-rw-r--r-- | tests/plugins/http/http_plugin_test.go | 64 |
2 files changed, 81 insertions, 0 deletions
diff --git a/tests/plugins/http/configs/.rr-no-http.yaml b/tests/plugins/http/configs/.rr-no-http.yaml new file mode 100644 index 00000000..6466c950 --- /dev/null +++ b/tests/plugins/http/configs/.rr-no-http.yaml @@ -0,0 +1,17 @@ +rpc: + listen: tcp://127.0.0.1:6001 + disabled: false + +server: + command: "php ../../http/client.php echo pipes" + user: "" + group: "" + env: + "RR_HTTP": "true" + relay: "pipes" + relay_timeout: "20s" + +logs: + mode: development + level: error + diff --git a/tests/plugins/http/http_plugin_test.go b/tests/plugins/http/http_plugin_test.go index 88857df5..356e7549 100644 --- a/tests/plugins/http/http_plugin_test.go +++ b/tests/plugins/http/http_plugin_test.go @@ -107,6 +107,70 @@ func TestHTTPInit(t *testing.T) { wg.Wait() } +func TestHTTPNoConfigSection(t *testing.T) { + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) + assert.NoError(t, err) + + cfg := &config.Viper{ + Path: "configs/.rr-no-http.yaml", + Prefix: "rr", + } + + err = cont.RegisterAll( + cfg, + &logger.ZapLogger{}, + &server.Plugin{}, + &httpPlugin.Plugin{}, + ) + assert.NoError(t, err) + + err = cont.Init() + if err != nil { + t.Fatal(err) + } + + ch, err := cont.Serve() + assert.NoError(t, err) + + 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 := <-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: + // timeout + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + return + } + } + }() + + stopCh <- struct{}{} + wg.Wait() +} + func TestHTTPInformerReset(t *testing.T) { cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) assert.NoError(t, err) |