File: debug_test.go

package info (click to toggle)
docker.io 26.1.5%2Bdfsg1-9
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 68,576 kB
  • sloc: sh: 5,748; makefile: 912; ansic: 664; asm: 228; python: 162
file content (43 lines) | stat: -rw-r--r-- 916 bytes parent folder | download | duplicates (2)
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/cli/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")
	}
}