2016-12-12 03:33:58 -05:00
|
|
|
package debug
|
2016-02-01 18:09:25 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-02-01 18:09:25 -05:00
|
|
|
)
|
|
|
|
|
2016-12-12 03:33:58 -05:00
|
|
|
func TestEnable(t *testing.T) {
|
2016-02-01 18:09:25 -05:00
|
|
|
defer func() {
|
|
|
|
os.Setenv("DEBUG", "")
|
|
|
|
logrus.SetLevel(logrus.InfoLevel)
|
|
|
|
}()
|
2016-12-12 03:33:58 -05:00
|
|
|
Enable()
|
2016-02-01 18:09:25 -05:00
|
|
|
if os.Getenv("DEBUG") != "1" {
|
|
|
|
t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG"))
|
|
|
|
}
|
|
|
|
if logrus.GetLevel() != logrus.DebugLevel {
|
|
|
|
t.Fatalf("expected log level %v, got %v\n", logrus.DebugLevel, logrus.GetLevel())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-12 03:33:58 -05:00
|
|
|
func TestDisable(t *testing.T) {
|
|
|
|
Disable()
|
2016-02-01 18:09:25 -05:00
|
|
|
if os.Getenv("DEBUG") != "" {
|
|
|
|
t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG"))
|
|
|
|
}
|
|
|
|
if logrus.GetLevel() != logrus.InfoLevel {
|
|
|
|
t.Fatalf("expected log level %v, got %v\n", logrus.InfoLevel, logrus.GetLevel())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-12 03:33:58 -05:00
|
|
|
func TestEnabled(t *testing.T) {
|
|
|
|
Enable()
|
|
|
|
if !IsEnabled() {
|
2016-02-01 18:09:25 -05:00
|
|
|
t.Fatal("expected debug enabled, got false")
|
|
|
|
}
|
2016-12-12 03:33:58 -05:00
|
|
|
Disable()
|
|
|
|
if IsEnabled() {
|
2016-02-01 18:09:25 -05:00
|
|
|
t.Fatal("expected debug disabled, got true")
|
|
|
|
}
|
|
|
|
}
|