make the log level env variable a string

This commit is contained in:
Marten Seemann 2017-06-07 10:38:35 +02:00
parent 7bad019ac2
commit 03ee31d26b
No known key found for this signature in database
GPG key ID: 3603F40B121FCDEA
3 changed files with 49 additions and 28 deletions

View file

@ -97,20 +97,37 @@ var _ = Describe("Log", func() {
Expect(Debug()).To(BeTrue())
})
It("reads log level from env", func() {
Expect(logLevel).To(Equal(LogLevelNothing))
os.Setenv(logEnv, "3")
readLoggingEnv()
Expect(logLevel).To(Equal(LogLevelDebug))
})
Context("reading from env", func() {
BeforeEach(func() {
Expect(logLevel).To(Equal(LogLevelNothing))
})
It("does not error reading invalid log levels from env", func() {
Expect(logLevel).To(Equal(LogLevelNothing))
os.Setenv(logEnv, "")
readLoggingEnv()
Expect(logLevel).To(Equal(LogLevelNothing))
os.Setenv(logEnv, "asdf")
readLoggingEnv()
Expect(logLevel).To(Equal(LogLevelNothing))
It("reads DEBUG", func() {
os.Setenv(logEnv, "DEBUG")
readLoggingEnv()
Expect(logLevel).To(Equal(LogLevelDebug))
})
It("reads INFO", func() {
os.Setenv(logEnv, "INFO")
readLoggingEnv()
Expect(logLevel).To(Equal(LogLevelInfo))
})
It("reads ERROR", func() {
os.Setenv(logEnv, "ERROR")
readLoggingEnv()
Expect(logLevel).To(Equal(LogLevelError))
})
It("does not error reading invalid log levels from env", func() {
Expect(logLevel).To(Equal(LogLevelNothing))
os.Setenv(logEnv, "")
readLoggingEnv()
Expect(logLevel).To(Equal(LogLevelNothing))
os.Setenv(logEnv, "asdf")
readLoggingEnv()
Expect(logLevel).To(Equal(LogLevelNothing))
})
})
})