github.com/wozhu6104/docker@v20.10.10+incompatible/cli/debug/debug_test.go (about)

     1  package debug // import "github.com/docker/docker/cli/debug"
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/sirupsen/logrus"
     8  )
     9  
    10  func TestEnable(t *testing.T) {
    11  	defer func() {
    12  		os.Setenv("DEBUG", "")
    13  		logrus.SetLevel(logrus.InfoLevel)
    14  	}()
    15  	Enable()
    16  	if os.Getenv("DEBUG") != "1" {
    17  		t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG"))
    18  	}
    19  	if logrus.GetLevel() != logrus.DebugLevel {
    20  		t.Fatalf("expected log level %v, got %v\n", logrus.DebugLevel, logrus.GetLevel())
    21  	}
    22  }
    23  
    24  func TestDisable(t *testing.T) {
    25  	Disable()
    26  	if os.Getenv("DEBUG") != "" {
    27  		t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG"))
    28  	}
    29  	if logrus.GetLevel() != logrus.InfoLevel {
    30  		t.Fatalf("expected log level %v, got %v\n", logrus.InfoLevel, logrus.GetLevel())
    31  	}
    32  }
    33  
    34  func TestEnabled(t *testing.T) {
    35  	Enable()
    36  	if !IsEnabled() {
    37  		t.Fatal("expected debug enabled, got false")
    38  	}
    39  	Disable()
    40  	if IsEnabled() {
    41  		t.Fatal("expected debug disabled, got true")
    42  	}
    43  }