-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathdebug_test.go
More file actions
54 lines (44 loc) · 1.02 KB
/
debug_test.go
File metadata and controls
54 lines (44 loc) · 1.02 KB
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
44
45
46
47
48
49
50
51
52
53
54
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0
package validate
import (
"os"
"sync"
"testing"
"github.com/go-openapi/testify/v2/assert"
)
var (
logMutex = &sync.Mutex{}
)
func TestDebug(t *testing.T) {
if !enableLongTests {
skipNotify(t)
t.SkipNow()
}
// standard lib t.TempDir() is still subject to an issue https://github.com/golang/go/issues/71544
// Hence: usetesting linter disabled
tmpFile, _ := os.CreateTemp("", "debug-test") //nolint:usetesting
tmpName := tmpFile.Name()
defer func() {
Debug = false
// mutex for -race
logMutex.Unlock()
os.Remove(tmpName)
}()
// mutex for -race
logMutex.Lock()
Debug = true
debugOptions()
defer func() {
validateLogger.SetOutput(os.Stdout)
}()
validateLogger.SetOutput(tmpFile)
debugLog("A debug")
Debug = false
tmpFile.Close()
flushed, _ := os.Open(tmpName)
buf := make([]byte, 500)
_, _ = flushed.Read(buf)
validateLogger.SetOutput(os.Stdout)
assert.Contains(t, string(buf), "A debug")
}