MCPcopy
hub / github.com/SurgeDM/Surge / TestDebug_CreatesLogFile

Function TestDebug_CreatesLogFile

internal/utils/debug_test.go:15–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestDebug_CreatesLogFile(t *testing.T) {
16 // Note: Debug uses sync.Once, so we can only test it once per test run
17 // This test verifies that the debug function creates a log file
18
19 // Ensure logs directory exists
20 logsDir := config.GetLogsDir()
21 if err := os.MkdirAll(logsDir, 0o755); err != nil {
22 t.Fatalf("Failed to create logs directory: %v", err)
23 }
24
25 // Call Debug
26 utils.Debug("Test message from unit test")
27
28 // Wait a moment for file to be created
29 time.Sleep(100 * time.Millisecond)
30
31 // Check if any debug log file was created
32 entries, err := os.ReadDir(logsDir)
33 if err != nil {
34 t.Fatalf("Failed to read logs directory: %v", err)
35 }
36
37 found := false
38 for _, entry := range entries {
39 if strings.HasPrefix(entry.Name(), "debug-") && strings.HasSuffix(entry.Name(), ".log") {
40 found = true
41 break
42 }
43 }
44
45 if !found {
46 t.Log("Note: Debug log file may not be created on first run due to sync.Once behavior")
47 }
48}
49
50func TestDebug_FormatsMessage(t *testing.T) {
51 // Test that Debug can handle format strings with arguments

Callers

nothing calls this directly

Calls 2

GetLogsDirFunction · 0.92
DebugFunction · 0.92

Tested by

no test coverage detected