@@ -2,6 +2,7 @@ package integration
22
33import (
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
0 commit comments