diff options
author | Valery Piashchynski <[email protected]> | 2021-01-18 23:20:39 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-18 23:20:39 +0300 |
commit | 8704e833dffd7d41614830b5347ba15fa9f297fd (patch) | |
tree | 3672285982b1f43212ffdb5d9958b6cc66774087 /tests/plugins/http/http_plugin_test.go | |
parent | a9a206b31e272e0508fff496e9641c4db291ddb7 (diff) | |
parent | 6d2c56b7fb8d33a4a8dcb2dad5d60e422c55d4df (diff) |
Merge pull request #485 from spiral/bug/nil_http_config
bug(http): NPE when config didn't contain HTTP section
Diffstat (limited to 'tests/plugins/http/http_plugin_test.go')
-rw-r--r-- | tests/plugins/http/http_plugin_test.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/plugins/http/http_plugin_test.go b/tests/plugins/http/http_plugin_test.go index 88857df5..3aa0f57a 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 + } + } + }() + + time.Sleep(time.Second * 2) + stopCh <- struct{}{} + wg.Wait() +} + func TestHTTPInformerReset(t *testing.T) { cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) assert.NoError(t, err) |