github.com/go/docker@v1.12.0-rc2/utils/debug_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/Sirupsen/logrus"
     8  )
     9  
    10  func TestEnableDebug(t *testing.T) {
    11  	defer func() {
    12  		os.Setenv("DEBUG", "")
    13  		logrus.SetLevel(logrus.InfoLevel)
    14  	}()
    15  	EnableDebug()
    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 TestDisableDebug(t *testing.T) {
    25  	DisableDebug()
    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 TestDebugEnabled(t *testing.T) {
    35  	EnableDebug()
    36  	if !IsDebugEnabled() {
    37  		t.Fatal("expected debug enabled, got false")
    38  	}
    39  	DisableDebug()
    40  	if IsDebugEnabled() {
    41  		t.Fatal("expected debug disabled, got true")
    42  	}
    43  }