Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 9a9826f

Browse files
committed
Add integration tests and fix issue
1 parent f40bafa commit 9a9826f

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

integration/main_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package integration
22

33
import (
44
"bufio"
5+
"bytes"
56
"crypto/tls"
67
"encoding/json"
78
"errors"
@@ -618,6 +619,78 @@ var _ = Describe("Router Integration", func() {
618619
Consistently(contentsFunc).ShouldNot(ContainSubstring("Component Router registered successfully"))
619620
})
620621

622+
Context("It starts up a debugserver", func() {
623+
var (
624+
testState *testState
625+
contentsFunc func() string = func() string {
626+
return string(gorouterSession.Out.Contents())
627+
}
628+
)
629+
630+
BeforeEach(func() {
631+
632+
testState = NewTestState()
633+
testState.cfg.DebugAddr = "127.0.0.1:17017"
634+
gorouterSession = testState.StartGorouter()
635+
})
636+
637+
It("can change the debugserver's logging level", func() {
638+
639+
Consistently(contentsFunc).ShouldNot(ContainSubstring(`{log_level":0,"timestamp"`))
640+
641+
request, err := http.NewRequest("PUT", fmt.Sprintf("http://%s/log-level", testState.cfg.DebugAddr), bytes.NewBufferString("debug"))
642+
Expect(err).NotTo(HaveOccurred())
643+
644+
response, err := http.DefaultClient.Do(request)
645+
Expect(err).NotTo(HaveOccurred())
646+
647+
Expect(response.StatusCode).To(Equal(http.StatusOK))
648+
response.Body.Close()
649+
650+
Consistently(contentsFunc).Should(ContainSubstring(`{"log_level":0,"timestamp"`))
651+
652+
// And back to info level
653+
gorouterSession.Out.Clear()
654+
request, err = http.NewRequest("PUT", fmt.Sprintf("http://%s/log-level", testState.cfg.DebugAddr), bytes.NewBufferString("info"))
655+
Expect(err).NotTo(HaveOccurred())
656+
657+
response, err = http.DefaultClient.Do(request)
658+
Expect(err).NotTo(HaveOccurred())
659+
660+
Expect(response.StatusCode).To(Equal(http.StatusOK))
661+
response.Body.Close()
662+
663+
//Terminate everything just to generate some info logs
664+
testState.StopAndCleanup()
665+
666+
Consistently(contentsFunc).ShouldNot(ContainSubstring(`{"log_level":0,"timestamp"`))
667+
Eventually(contentsFunc).Should(ContainSubstring(`{"log_level":1,"timestamp"`))
668+
669+
})
670+
671+
It("Does not accept invalid debug levels", func() {
672+
673+
Consistently(contentsFunc).ShouldNot(ContainSubstring(`{log_level":0,"timestamp"`))
674+
675+
gorouterSession.Out.Clear()
676+
677+
request, err := http.NewRequest("PUT", fmt.Sprintf("http://%s/log-level", testState.cfg.DebugAddr), bytes.NewBufferString("meow"))
678+
Expect(err).NotTo(HaveOccurred())
679+
680+
response, err := http.DefaultClient.Do(request)
681+
Expect(err).NotTo(HaveOccurred())
682+
683+
Expect(response.StatusCode).To(Equal(http.StatusOK))
684+
response.Body.Close()
685+
686+
Expect(gorouterSession.ExitCode()).To(Equal(-1))
687+
688+
Consistently(contentsFunc).ShouldNot(ContainSubstring(`{"log_level":0,"timestamp"`))
689+
Eventually(contentsFunc).Should(ContainSubstring(`{"log_level":1,"timestamp"`))
690+
})
691+
692+
})
693+
621694
Describe("loggregator metrics emitted", func() {
622695
var (
623696
fakeMetron test_util.FakeMetron

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func main() {
106106
}
107107

108108
if c.DebugAddr != "" {
109-
_, err = debugserver.Run(c.DebugAddr, *grlog.Conf)
109+
_, err = debugserver.Run(c.DebugAddr, &grlog.Conf)
110110
if err != nil {
111111
logger.Error("failed-to-start-debug-server", grlog.ErrAttr(err))
112112
}

0 commit comments

Comments
 (0)