File: debug_test.go

package info (click to toggle)
docker.io 27.5.1%2Bdfsg4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,384 kB
  • sloc: sh: 5,847; makefile: 1,146; ansic: 664; python: 162; asm: 133
file content (43 lines) | stat: -rw-r--r-- 924 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package debug // import "github.com/docker/docker/cmd/dockerd/debug"

import (
	"os"
	"testing"

	"github.com/containerd/log"
)

func TestEnable(t *testing.T) {
	t.Cleanup(func() {
		_ = os.Setenv("DEBUG", "")
		_ = log.SetLevel("info")
	})
	Enable()
	if debug := os.Getenv("DEBUG"); debug != "1" {
		t.Fatalf("expected DEBUG=1, got %s", debug)
	}
	if lvl := log.GetLevel(); lvl != log.DebugLevel {
		t.Fatalf("expected log level %v, got %v", log.DebugLevel, lvl)
	}
}

func TestDisable(t *testing.T) {
	Disable()
	if debug := os.Getenv("DEBUG"); debug != "" {
		t.Fatalf(`expected DEBUG="", got %s`, debug)
	}
	if lvl := log.GetLevel(); lvl != log.InfoLevel {
		t.Fatalf("expected log level %v, got %v", log.InfoLevel, lvl)
	}
}

func TestEnabled(t *testing.T) {
	Enable()
	if !IsEnabled() {
		t.Fatal("expected debug enabled, got false")
	}
	Disable()
	if IsEnabled() {
		t.Fatal("expected debug disabled, got true")
	}
}