-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathdebug_test.go
More file actions
46 lines (37 loc) · 1.02 KB
/
debug_test.go
File metadata and controls
46 lines (37 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
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0
package spec
import (
"os"
"sync"
"testing"
"github.com/go-openapi/testify/v2/assert"
)
var logMutex = &sync.Mutex{} //nolint:gochecknoglobals // test fixture
func TestDebug(t *testing.T) {
// usetesting linter disabled until https://github.com/golang/go/issues/71544 is fixed for windows
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() {
specLogger.SetOutput(os.Stdout)
}()
specLogger.SetOutput(tmpFile)
debugLog("A debug")
Debug = false
_ = tmpFile.Close()
flushed, _ := os.Open(tmpName) //nolint:gosec // test file, path is from os.CreateTemp
buf := make([]byte, 500)
_, _ = flushed.Read(buf)
specLogger.SetOutput(os.Stdout)
assert.StringContainsT(t, string(buf), "A debug")
}