2018-02-05 21:05:59 +00:00
|
|
|
package debug // import "github.com/docker/docker/cli/debug"
|
2016-02-01 23:09:25 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2023-09-13 15:41:45 +00:00
|
|
|
"github.com/containerd/log"
|
2016-02-01 23:09:25 +00:00
|
|
|
)
|
|
|
|
|
2016-12-12 08:33:58 +00:00
|
|
|
func TestEnable(t *testing.T) {
|
2023-07-30 15:18:56 +00:00
|
|
|
t.Cleanup(func() {
|
|
|
|
_ = os.Setenv("DEBUG", "")
|
|
|
|
_ = log.SetLevel("info")
|
|
|
|
})
|
2016-12-12 08:33:58 +00:00
|
|
|
Enable()
|
2023-07-30 15:18:56 +00:00
|
|
|
if debug := os.Getenv("DEBUG"); debug != "1" {
|
|
|
|
t.Fatalf("expected DEBUG=1, got %s", debug)
|
2016-02-01 23:09:25 +00:00
|
|
|
}
|
2023-07-30 15:18:56 +00:00
|
|
|
if lvl := log.GetLevel(); lvl != log.DebugLevel {
|
|
|
|
t.Fatalf("expected log level %v, got %v", log.DebugLevel, lvl)
|
2016-02-01 23:09:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-12 08:33:58 +00:00
|
|
|
func TestDisable(t *testing.T) {
|
|
|
|
Disable()
|
2023-07-30 15:18:56 +00:00
|
|
|
if debug := os.Getenv("DEBUG"); debug != "" {
|
|
|
|
t.Fatalf(`expected DEBUG="", got %s`, debug)
|
2016-02-01 23:09:25 +00:00
|
|
|
}
|
2023-07-30 15:18:56 +00:00
|
|
|
if lvl := log.GetLevel(); lvl != log.InfoLevel {
|
|
|
|
t.Fatalf("expected log level %v, got %v", log.InfoLevel, lvl)
|
2016-02-01 23:09:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-12 08:33:58 +00:00
|
|
|
func TestEnabled(t *testing.T) {
|
|
|
|
Enable()
|
|
|
|
if !IsEnabled() {
|
2016-02-01 23:09:25 +00:00
|
|
|
t.Fatal("expected debug enabled, got false")
|
|
|
|
}
|
2016-12-12 08:33:58 +00:00
|
|
|
Disable()
|
|
|
|
if IsEnabled() {
|
2016-02-01 23:09:25 +00:00
|
|
|
t.Fatal("expected debug disabled, got true")
|
|
|
|
}
|
|
|
|
}
|