Skip to content

Commit

Permalink
Add integration tests and fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcPaquette committed Oct 31, 2024
1 parent f40bafa commit 9a9826f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
73 changes: 73 additions & 0 deletions integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration

import (
"bufio"
"bytes"
"crypto/tls"
"encoding/json"
"errors"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit 9a9826f

Please sign in to comment.