sink *lager.ReconfigurableSink ) BeforeEach(func() { testSink = lagertest.NewTestSink() sink = lager.NewReconfigurableSink(testSink, lager.INFO) }) It("returns the current level", func() { Expect(sink.GetMinLevel()).To(Equal(lager.INFO)) }) Context("when logging above the minimum log level", func() { BeforeEach(func() { sink.Log(lager.INFO, []byte("hello world")) }) It("writes to the given sink", func() { Expect(testSink.Buffer()).To(gbytes.Say("hello world\n")) }) }) Context("when logging below the minimum log level", func() { BeforeEach(func() { sink.Log(lager.DEBUG, []byte("hello world")) }) It("does not write to the given writer", func() { Expect(testSink.Buffer().Contents()).To(BeEmpty()) })
lager.ERROR: []string{"error", "ERROR", "e", strconv.Itoa(int(lager.ERROR))}, lager.FATAL: []string{"fatal", "FATAL", "f", strconv.Itoa(int(lager.FATAL))}, } //This will add another 16 unit tests to the suit for level, acceptedForms := range validForms { for _, form := range acceptedForms { testLevel := level testForm := form It("can reconfigure the given sink with "+form, func() { var err error process, err = cf_debug_server.Run(address, sink) Expect(err).NotTo(HaveOccurred()) sink.Log(testLevel, []byte("hello before level change")) Eventually(logBuf).ShouldNot(gbytes.Say("hello before level change")) request, err := http.NewRequest("PUT", fmt.Sprintf("http://%s/log-level", address), bytes.NewBufferString(testForm)) Expect(err).NotTo(HaveOccurred()) response, err := http.DefaultClient.Do(request) Expect(err).NotTo(HaveOccurred()) Expect(response.StatusCode).To(Equal(http.StatusOK)) response.Body.Close() sink.Log(testLevel, []byte("Logs sent with log-level "+testForm)) Eventually(logBuf).Should(gbytes.Say("Logs sent with log-level " + testForm)) })