From 9a9826f2e936f29bbcb4206c71b22ce94070dde5 Mon Sep 17 00:00:00 2001 From: Marc Paquette Date: Thu, 31 Oct 2024 14:03:07 +0000 Subject: [PATCH] Add integration tests and fix issue --- integration/main_test.go | 73 ++++++++++++++++++++++++++++++++++++++++ main.go | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/integration/main_test.go b/integration/main_test.go index 7827c913..2f1c8a46 100644 --- a/integration/main_test.go +++ b/integration/main_test.go @@ -2,6 +2,7 @@ package integration import ( "bufio" + "bytes" "crypto/tls" "encoding/json" "errors" @@ -618,6 +619,78 @@ var _ = Describe("Router Integration", func() { Consistently(contentsFunc).ShouldNot(ContainSubstring("Component Router registered successfully")) }) + Context("It starts up a debugserver", func() { + var ( + testState *testState + contentsFunc func() string = func() string { + return string(gorouterSession.Out.Contents()) + } + ) + + BeforeEach(func() { + + testState = NewTestState() + testState.cfg.DebugAddr = "127.0.0.1:17017" + gorouterSession = testState.StartGorouter() + }) + + It("can change the debugserver's logging level", func() { + + Consistently(contentsFunc).ShouldNot(ContainSubstring(`{log_level":0,"timestamp"`)) + + request, err := http.NewRequest("PUT", fmt.Sprintf("http://%s/log-level", testState.cfg.DebugAddr), bytes.NewBufferString("debug")) + Expect(err).NotTo(HaveOccurred()) + + response, err := http.DefaultClient.Do(request) + Expect(err).NotTo(HaveOccurred()) + + Expect(response.StatusCode).To(Equal(http.StatusOK)) + response.Body.Close() + + Consistently(contentsFunc).Should(ContainSubstring(`{"log_level":0,"timestamp"`)) + + // And back to info level + gorouterSession.Out.Clear() + request, err = http.NewRequest("PUT", fmt.Sprintf("http://%s/log-level", testState.cfg.DebugAddr), bytes.NewBufferString("info")) + Expect(err).NotTo(HaveOccurred()) + + response, err = http.DefaultClient.Do(request) + Expect(err).NotTo(HaveOccurred()) + + Expect(response.StatusCode).To(Equal(http.StatusOK)) + response.Body.Close() + + //Terminate everything just to generate some info logs + testState.StopAndCleanup() + + Consistently(contentsFunc).ShouldNot(ContainSubstring(`{"log_level":0,"timestamp"`)) + Eventually(contentsFunc).Should(ContainSubstring(`{"log_level":1,"timestamp"`)) + + }) + + It("Does not accept invalid debug levels", func() { + + Consistently(contentsFunc).ShouldNot(ContainSubstring(`{log_level":0,"timestamp"`)) + + gorouterSession.Out.Clear() + + request, err := http.NewRequest("PUT", fmt.Sprintf("http://%s/log-level", testState.cfg.DebugAddr), bytes.NewBufferString("meow")) + Expect(err).NotTo(HaveOccurred()) + + response, err := http.DefaultClient.Do(request) + Expect(err).NotTo(HaveOccurred()) + + Expect(response.StatusCode).To(Equal(http.StatusOK)) + response.Body.Close() + + Expect(gorouterSession.ExitCode()).To(Equal(-1)) + + Consistently(contentsFunc).ShouldNot(ContainSubstring(`{"log_level":0,"timestamp"`)) + Eventually(contentsFunc).Should(ContainSubstring(`{"log_level":1,"timestamp"`)) + }) + + }) + Describe("loggregator metrics emitted", func() { var ( fakeMetron test_util.FakeMetron diff --git a/main.go b/main.go index 97dc38ef..030e2a8e 100644 --- a/main.go +++ b/main.go @@ -106,7 +106,7 @@ func main() { } if c.DebugAddr != "" { - _, err = debugserver.Run(c.DebugAddr, *grlog.Conf) + _, err = debugserver.Run(c.DebugAddr, &grlog.Conf) if err != nil { logger.Error("failed-to-start-debug-server", grlog.ErrAttr(err)) }