| 85 | } |
| 86 | |
| 87 | func TestLoggerIsolation(t *testing.T) { |
| 88 | ctxA := context.Background() |
| 89 | ctxB := context.Background() |
| 90 | |
| 91 | loggerA, _ := LoggerFor(ctxA) |
| 92 | loggerA.Name("A") |
| 93 | defer loggerA.Close() |
| 94 | defer os.Remove(loggerA.LogFile()) |
| 95 | |
| 96 | loggerB, _ := LoggerFor(ctxB) |
| 97 | loggerB.Name("B") |
| 98 | defer loggerB.Close() |
| 99 | defer os.Remove(loggerB.LogFile()) |
| 100 | |
| 101 | loggerA.Log("only in A") |
| 102 | loggerB.Log("only in B") |
| 103 | |
| 104 | loggerA.Close() |
| 105 | loggerB.Close() |
| 106 | |
| 107 | contentA, err := os.ReadFile(loggerA.LogFile()) |
| 108 | require.NoError(t, err) |
| 109 | contentB, err := os.ReadFile(loggerB.LogFile()) |
| 110 | require.NoError(t, err) |
| 111 | |
| 112 | assert.Contains(t, string(contentA), "only in A") |
| 113 | assert.NotContains(t, string(contentA), "only in B") |
| 114 | assert.Contains(t, string(contentB), "only in B") |
| 115 | assert.NotContains(t, string(contentB), "only in A") |
| 116 | } |
| 117 | |
| 118 | func TestLogFileCreatesTemporaryFile(t *testing.T) { |
| 119 | ctx := context.Background() |